我一直试图简单地将字符串"1998-04-11"转换为UNIX时间戳,根据在线转换器应该是892245600.
但我一直得到不同的结果.
struct tm tm;
time_t ts;
strptime("1998-04-11", "%Y-%m-%d", &tm);
tm.tm_mon = tm.tm_mon -1;
ts = mktime(&tm);
printf("%d \n", (int)ts); //unix time-stamp
printf("%s \n", ctime(&ts)); //human readable date
Run Code Online (Sandbox Code Playgroud)
结果:
893502901
Sat Apr 25 13:15:01 1998
Run Code Online (Sandbox Code Playgroud)
谁能告诉我我做错了什么?