如何在Arduino上将时间设置为中央时区?

问题描述 投票:0回答:1

我试图弄清楚如何将esp8266板上的时间设置为中央时区。

我尝试了以下操作,但似乎没有什么不同。

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);

您能告诉我我做错了什么,还是推荐一个可以用来实现这一目标的库?谢谢!

c++ arduino esp8266 arduino-esp8266 arduino-c++
1个回答
1
投票

我知道了。

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();
© www.soinside.com 2019 - 2024. All rights reserved.