【发布时间】:2021-05-06 07:12:02
【问题描述】:
我需要在 Linux 上使用 GCC 来获取 UTC 和本地时间之间的差异。
似乎首选的方法是检查struct tm 由localtime 函数返回的tm_gmtoff 字段。
https://stackoverflow.com/a/47218792
但是,tm_gmtoff 没有记录在 localtime 的手册页中,但是
只有tm_zone 是。
https://man7.org/linux/man-pages/man3/localtime.3.html
头文件中似乎存在tm_gmtoff 和tm_zone。
19 # ifdef __USE_MISC
20 long int tm_gmtoff; /* Seconds east of UTC. */
21 const char *tm_zone; /* Timezone abbreviation. */
22 # else
23 long int __tm_gmtoff; /* Seconds east of UTC. */
24 const char *__tm_zone; /* Timezone abbreviation. */
25 # endif
我不确定为什么手册页中省略了tm_gmtoff。会不会是以下提交中引入的手册页错误?
【问题讨论】:
-
Here 它说:
The tm_gmtoff field is derived from BSD and is a GNU library extension; it is not visible in a strict ISO C environment. -
@ssbssa 但它也对
tm_zone说同样的话:Like tm_gmtoff, this field is a BSD and GNU extension, and is not visible in a strict ISO C environment.