I need to get the difference between UTC and the local time using GCC on Linux.
It seems that the preferred way is to examine tm_gmtoff
field of a struct tm
returned by localtime
function.
https://stackoverflow.com/a/47218792
However, tm_gmtoff
is not documented in the man page of localtime
, but
only tm_zone
is.
https://man7.org/linux/man-pages/man3/localtime.3.html
It looks like tm_gmtoff
and tm_zone
exist in the header file.
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
I’m not sure why tm_gmtoff
is omitted in the man page. Could it be a man-page bug introduced in the following commit?
Advertisement
Answer
I reported this to the maintainers. It has been fixed by the following commit.