时间戳及其字符串转换

 1 #include <time.h>
 2 
 3 time_t timestamp = time(NULL); //1506349871
 4 
 5 void ConvertTimestampToString(time_t timestamp, string& timestr)
 6 {
 7     struct tm *tmp;
 8     timestamp += 28800;
 9     tmp = gmtime(&timestamp);
10     char s[30];
11     strftime(s, 30, "%Y-%m-%d %H:%M:%S", tmp);
12     timestr = s; //2017-09-25 22:31:11
13 }

 

posted @ 2017-09-25 22:32  lausaa  阅读(203)  评论(0编辑  收藏  举报