Search code examples
c++arduinoesp8266arduino-esp8266arduino-c++

How to set the time to central time zone on Arduino?


I am trying to figure out how to set the time on the esp8266 board to Central Time Zone.

I have tried the following but it doesn't seem to make a difference.

configTime(-5*3600, 3600, "pool.ntp.org", "time.nist.gov");

time(&curr_time);
curr_tm = localtime(&curr_time);

char date_string[100];
char time_string[100];
char ampm_string[50];
char zone_string[50];

strftime(date_string, 50, "Today is %B %d, %Y", curr_tm);
strftime(time_string, 50, "Current time is %T", curr_tm);

Could you tell me what I am doing wrong or recommend a library I can use to achieve this?
Thank you!


Solution

  • I figured it out.

    configTime(0, 0, "pool.ntp.org", "time.nist.gov");
    setenv("TZ", "CST6CDT,M3.2.0/02:00:00,M11.1.0/02:00:00", 1);  
    tzset();