![](/img/trans.png)
[英]Why does tm_mday start from 1 while all other elements of struct tm start from 0?
[英]timegm on struct tm: Where year = 70 mon = 1 mday = 1 does not return 0 seconds?
給定以下內容:
struct tm tm;
time_t gps_epoch_to_epoch_diff;
memset(&tm, 0, sizeof(struct tm));
tm.tm_year = 70;
tm.tm_mon = 1;
tm.tm_mday = 1;
gps_epoch_to_epoch_diff = timegm(&tm);
printf("sec = %lus\n", gps_epoch_to_epoch_diff);
我希望輸出是
秒= 0秒
但是,我得到:
秒= 2678400s
為什么?
tm.tm_year = 70;
tm.tm_mon = 1;
tm.tm_mday = 1;
您正在使用1
作為2月,因為tm_mon是從零開始的 。 使用0
,您應該得到想要的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.