forked from espressif/esp-idf
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:
@@ -75,6 +75,9 @@ If you need to obtain time with one second resolution, use the following method:
|
|||||||
time(&now);
|
time(&now);
|
||||||
// Set timezone to China Standard Time
|
// Set timezone to China Standard Time
|
||||||
setenv("TZ", "CST-8", 1);
|
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();
|
tzset();
|
||||||
|
|
||||||
localtime_r(&now, &timeinfo);
|
localtime_r(&now, &timeinfo);
|
||||||
|
Reference in New Issue
Block a user