Timezone Not Working Properly
Posted: Wed Dec 09, 2020 5:48 am
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);
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);