OpenWeather icon indicating copy to clipboard operation
OpenWeather copied to clipboard

Convert UNIX time to string variable

Open Raynman77 opened this issue 2 years ago • 3 comments

In the example "examples/Onecall API (subscription required)/My_OpenWeather_Test/My_OpenWeather_Test.ino", there is a define, #define TIME_OFFSET 1UL * 3600UL // UTC + 0 hour I'm trying to understand how I can set the offset given this example, when the unsigned long variables are used but my timezone offset is -5? Please forgive me as I am extremely novice when it comes to C & C++. String strTime(time_t unixTime) { unixTime += TIME_OFFSET; return ctime(&unixTime); }

Raynman77 avatar Jul 15 '23 21:07 Raynman77

This should work:

#define TIME_OFFSET -5 * 3600

You might need to cast the time_t type if you get a compile error:

unixTime = (time_t)((int32_t)unixTime + (int32_t)(TIME_OFFSET));

Bodmer avatar Jul 16 '23 08:07 Bodmer

This should work:

#define TIME_OFFSET -5 * 3600

You might need to cast the time_t type if you get a compile error:

unixTime = (time_t)((int32_t)unixTime + (int32_t)(TIME_OFFSET));

Thanks @Bodmer, any chance you might end up porting the Openweather API to PlatformIO? I noticed JSON_Decoder was available in the repo but didn't find Openweather in there.

Raynman77 avatar Jul 16 '23 14:07 Raynman77

+1 on platformio..struggling to get this in IDE

Grey-Lancaster avatar Jan 06 '24 21:01 Grey-Lancaster