C++时间戳获取及转换
- 时间戳的获取
time_t tCurrentTime = time(NULL); //秒
- 时间戳转换,格式化
string StampToTime (time_t tCurrentTime){
struct tm tm;
char strTimeType[11];
tm = *localtime(&tCurrentTime);
strftime(strTimeType,sizeof(strTimeType),"%Y%m%d%H",&tm);
string strTime(strTimeType);
return strTime;
}
- 输出格式
time_t 为int64类型,8字节,格式输出:%lld。