小编Pau*_*l A的帖子

Linux-x64 glibc:为什么2月1日在1月31日之前到来?

当你打电话给mktime()时,2月1日好像是在1月31日之前来的.为什么会这样呢?我做错了什么或者这是glibc中的错误?

这是代码:

struct tm tm;
time_t tt;

memset(&tm, 0, sizeof(tm));
tm.tm_year = 2011;
tm.tm_mon = 1;
tm.tm_mday = 31;
tm.tm_hour = 11;
tm.tm_min = 41;
tm.tm_sec = 28;
tm.tm_isdst = 0;
tt = mktime(&tm);

printf("Time now %d-%d-%d %d:%d:%d (%s) = %lu\n",
    tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_zone, tt);


memset(&tm, 0, sizeof(tm));
tm.tm_year = 2011;
tm.tm_mon = 2;
tm.tm_mday = 1;
tm.tm_hour = 1;
tm.tm_min = 1;
tm.tm_sec = 1;
tm.tm_isdst = 0;
tt = mktime(&tm);

printf("Time now %d-%d-%d %d:%d:%d …
Run Code Online (Sandbox Code Playgroud)

c c++ linux glibc mktime

10
推荐指数
1
解决办法
395
查看次数

标签 统计

c ×1

c++ ×1

glibc ×1

linux ×1

mktime ×1