core-system/newlib: updated docs to reflect that tzset() needs to be called before localtime/mktime()

According to the posix standard localtime/mktime should use timezone information as though localtime/mktime() calls tzset(),
but this is not the case in older versions of Newlib.

Closes https://github.com/espressif/esp-idf/issues/11455
This commit is contained in:
Marius Vikhammer
2023-05-24 16:13:34 +08:00
parent c25d92074e
commit aab35a2126

View File

@@ -75,6 +75,9 @@ If you need to obtain time with one second resolution, use the following method:
time(&now);
// Set timezone to China Standard Time
setenv("TZ", "CST-8", 1);
/* According to the posix standard localtime/mktime should use timezone information as though localtime/mktime() calls tzset(),
but this is not the case in older versions of Newlib. We manually call tzset to ensure the timezone info is updated*/
tzset();
localtime_r(&now, &timeinfo);