小编jdo*_*eer的帖子

将字符串时间转换为unix时间,反之亦然

我一直试图简单地将字符串"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)

谁能告诉我我做错了什么?

c++ unix-timestamp

7
推荐指数
1
解决办法
4376
查看次数

标签 统计

c++ ×1

unix-timestamp ×1