gpt4 book ai didi

c - 结构 tm : Where year = 70 mon = 1 mday = 1 does not return 0 seconds? 上的 timegm

转载 作者:太空宇宙 更新时间:2023-11-04 05:51:28 25 4
gpt4 key购买 nike

鉴于以下情况:

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);

我希望输出是

sec = 0s

但是,我得到:

sec = 2678400s

为什么?

最佳答案

tm.tm_year = 70;
tm.tm_mon = 1;
tm.tm_mday = 1;

您使用 1 作为月份,即二月,作为 tm_mon is zero-based .使用 0,您应该会得到想要的结果。

关于c - 结构 tm : Where year = 70 mon = 1 mday = 1 does not return 0 seconds? 上的 timegm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40642957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com