Open Duberry opened 2 weeks ago
Hi, thank you, how to convert UNIX sunrise/sunset time to your local time hours and minutes?
Hi, thank you, how to convert UNIX sunrise/sunset time to your local time hours and minutes?
"sys": {
"type": 2,
"id": 2075663,
"country": "IT",
"sunrise": 1661834187,
"sunset": 1661882248
},
// assume you use time.h and setup the device time something like this
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
struct tm timeinfo;
time_t sunrise_timestamp = 1661834187; // Example UNIX time
time_t sunset_timestamp = 1661882248; // Example UNIX time
struct tm sunrise_timeinfo;
localtime_r(&sunrise_timestamp , &timeinfo); //<-- This does the main work
Serial.printf("Converted local time: %02d:%02d:%02d\n",
sunrise_timeinfo.tm_hour,
sunrise_timeinfo.tm_min,
sunrise_timeinfo.tm_sec);
}
struct tm sunset_timeinfo ;
localtime_r(&sunset_timestamp , &timeinfo); //<-- This does the main work
Serial.printf("Converted local time: %02d:%02d:%02d\n",
sunset_timeinfo.tm_hour,
sunset_timeinfo.tm_min,
sunset_timeinfo.tm_sec);
}
openweather JSON includes the sunrise and sunset as UNIX epoch time.
Request to add a simple sunrise and sunset time screen?