Timezone Not Working Properly

weswitt
Posts: 2
Joined: Tue Aug 16, 2016 8:05 pm

Timezone Not Working Properly

Postby weswitt » 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);

otaviogomes
Posts: 1
Joined: Tue Nov 08, 2022 2:14 pm

Re: Timezone Not Working Properly

Postby otaviogomes » Tue Nov 08, 2022 2:16 pm

The same problem here. ESP-IDF v4.4.2.

Sprite
Espressif staff
Espressif staff
Posts: 10612
Joined: Thu Nov 26, 2015 4:08 am

Re: Timezone Not Working Properly

Postby Sprite » Wed Nov 09, 2022 12:45 am

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