Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "time.h"
- const char* ntpServer = "pool.ntp.org";
- const long gmtOffset_sec = 3600; // Adjust according to timezone
- const int daylightOffset_sec = 3600;
- void setup() {
- Serial.begin(115200);
- // Configure and start NTP for time synchronization
- configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
- struct tm timeinfo;
- if (getLocalTime(&timeinfo)) {
- Serial.println("Current time:");
- Serial.printf("%02d:%02d:%02d\n", timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
- } else {
- Serial.println("Failed to obtain time");
- }
- }
- void loop() {
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement