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

标签 c++ arduino esp8266 arduino-esp8266 arduino-c++

我想弄清楚如何将 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);

你能告诉我我做错了什么或者推荐一个我可以用来实现这个目标的库吗?
谢谢!

最佳答案

我想通了。

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

关于c++ - 如何在 Arduino 上将时间设置为中央时区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59039946/

相关文章:

sdk - RTOS SDK app_main在哪里定义为启动函数?

c++ - 如何在QT中绘制一条经过多个点的平滑曲线?

c++ - 无法编译 unordered_set 包含来自 cppreference.com 的函数

c++ - OpenGL 应用程序的颜色选择器/选择器

c++ - 将构造函数中动态分配的数组分配给唯一的智能指针成员变量

c++ - Arduino:从两个十进制字符串中获取十六进制值

arduino - ESP8266 带弹出窗口的强制门户

arduino - 如何解决这个arduino error-error : pins_arduino. h: No such file or directory

string - 在 Arduino 上将 int 或 String 转换为 char 数组

c - AT 命令 ESP8266 01 : AT+CIPSTART: How to fix response Link type Error/Can't connect with TCP