I'm seeing that using tzset does not seem to work properly for my timezone. The following code yields the wrong time value:
gmt time: [Wed Dec 9 05:31:27 2020]
local time: [Wed Dec 9 13:31:27 2020]
The offset is "-8", but it is treating it as +8. Am I doing something wrong or is there a known bug here?
time(&now);
ti_gmt = gmtime(&now);
strftime(strftime_buf, sizeof(strftime_buf), "%c", ti_gmt);
printf("gmt time: [%s]\n", strftime_buf);
setenv("TZ", "PST-8PDT,M3.2.0/2,M11.2.0/2", 1);
tzset();
ti_local = localtime(&now);
strftime(strftime_buf, sizeof(strftime_buf), "%c", ti_local);
printf("local time: [%s]\n", strftime_buf);
Timezone Not Working Properly
-
otaviogomes
- Posts: 1
- Joined: Tue Nov 08, 2022 2:14 pm
Re: Timezone Not Working Properly
It's a POSIX quirk, not a bug. From e.g. https://www.gnu.org/software/libc/manua ... iable.html
The offset specifies the time value you must add to the local time to get a Coordinated Universal Time value. It has syntax like [+|-]hh[:mm[:ss]]. This is positive if the local time zone is west of the Prime Meridian and negative if it is east.
Who is online
Users browsing this forum: Semrush [Bot] and 4 guests
