But it displays the date/time 21 hours into the future.
It has a Timezone value, set to 3 by default, but the result time is the same regardless of the Timezone value.
(I'm in the US, CST time zone (GMT-06:00))
Any code corrections appreciated.
#include <ESP8266WiFi.h>
#include <time.h>
const char* ssid = "..........";
const char* password = "..........";
int timezone = 3;
int dst = 0;
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("\nConnecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1000);
}
configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");
Serial.println("\nWaiting for time");
while (!time(nullptr)) {
Serial.print(".");
delay(1000);
}
Serial.println("");
}
void loop() {
time_t now = time(nullptr);
Serial.println(ctime(&now));
delay(1000);
}