setenv and tzset not working
Posted: Mon Mar 09, 2026 12:35 pm
I'm using SNTP to set the system time and it's working fine. But then I try to set the local time;
time(&now);
setenv("TZ", "CST6CDT,M3.8.0/2,M11.1.0/2", 1);
tzset();
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
cli_print_msg("Local Time is: %s", strftime_buf);
gmt = gmtime(&now);
if(gmt) {
cli_print_msg("UTC time: %u/%u/%u %u:%u:%u", (gmt->tm_mon + 1),
gmt->tm_mday,
(gmt->tm_year - 100),
gmt->tm_hour,
gmt->tm_min,
gmt->tm_sec);
}
And it just returns GMT in the local time string. Is there some setup for setenv to work that I might be missing. When I look at the sample, it seems that everything I need is already setup by the time I have SNTP working.
time(&now);
setenv("TZ", "CST6CDT,M3.8.0/2,M11.1.0/2", 1);
tzset();
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
cli_print_msg("Local Time is: %s", strftime_buf);
gmt = gmtime(&now);
if(gmt) {
cli_print_msg("UTC time: %u/%u/%u %u:%u:%u", (gmt->tm_mon + 1),
gmt->tm_mday,
(gmt->tm_year - 100),
gmt->tm_hour,
gmt->tm_min,
gmt->tm_sec);
}
And it just returns GMT in the local time string. Is there some setup for setenv to work that I might be missing. When I look at the sample, it seems that everything I need is already setup by the time I have SNTP working.