当我执行下面的代码:
#include <time.h> #include <stdio.h> int main(int argc, char *argv[]) { time_t rawtime = 0; time_t secs; struct tm* timeinfo = gmtime(&rawtime); printf("rawtime : %s\n", asctime(timeinfo)); secs = mktime(timeinfo); printf("converted time : %s\n", asctime(gmtime(&secs))); return 0; }
输出是:
rawtime : Thu Jan 1 00:00:00 1970 converted time : Wed Dec 31 23:00:00 1969
为什么这一个小时的差异?
我正在运行Ubuntu 14.10 64位btw。
由于mktime将本地时间(而不是系统时间(gmtime))转换为时间戳。