The esp products use the standard POSIX time library functions.
time(), gmtime(), localtime(), mktime(), gettimeofday() etc.
You can google them to see how they work. (they haven't changed in decades)
To get the broken down into elements you pass a pointer to a time_t to localtime() that fills in the tm structure.
Then reference any member you need.
Hello, people. I'm attempting to change the SimpleTime example to show time on an LCD display. At the setup, if I write something in the LCD before the printLocalTime(), it works, but after the printLocalTime(), any call to the LCD functions is totally ignored. I can not find useful examples in the web… Some good soul can help me?
I think sticking with the bundled/built-in POSIX time API functions would be better as the API functions are well documented since they have't changed in like 40+ years and it is portable across all platforms including linux.
Just combine it with the ESP specific functions to set the TZ environment variable and NTP configuration to initialize things.
Your library is missing quite a bit as it is a wrapper for the bundled time functions but there there does not appear to be a way to set the TZ variable which configures the local timezone information,including DST rules, and it doesn't appear to be able to configure NTP.
I needed a way to set the time without using NTP. Might be helpful if you don't want to access the NTP server.
In this project, ESP32_OLED_BLE, I am setting the time via BLE from the phone's local time
fbiego:
I needed a way to set the time without using NTP. Might be helpful if you don't want to access the NTP server.
In this project, ESP32_OLED_BLE, I am setting the time via BLE from the phone's local time
You don't have to use NTP to use the time functions on the esp32.
RIN67630:
I got it to work, but I find it a bit clumsy and it gives me an offset of 8 hours.
??
Have you properly set up the TZ variable?
mktime() takes a local time not a GMT local time to generate the time_t value.
I haven't tested that the ESP32 mktime() works properly when using local time.
I set the time using GMT.
i.e.
I keep time in the RTC as GMT set the system time then set the TZ variable to get local time.