The ESP32 is a powerful and versatile microcontroller with an embedded RTC module. The RTC module enables tracking of the current date and time, including seconds, minutes, hours, day of the week, day of the month, month, and year. It supports both 24-hour and 12-hour formats.

By default, the RTC utilizes an Internal 150 kHz RC oscillator as its clock source, eliminating the need for external components. This configuration ensures the lowest deep-sleep current consumption.

However, it's important to note that the frequency stability of the internal clock source can be affected by temperature fluctuations, resulting in an approximate 5% error in the internal RTC clock frequency. Consequently, there could be a deviation of 180 seconds (3 minutes) per hour from the actual time. To mitigate this, regular NTP synchronization with the internal RTC is recommended.

The ESP32's RTC can operate in deep sleep mode while accurately maintaining timekeeping functionality. It consumes minimal power in this state, making it particularly suitable for battery-powered applications requiring long-term timekeeping.

In the code provided below, we will demonstrate how to set the RTC time using a Unix Timestamp and how to output the time to the Serial Monitor.


settimeofday() Set time with Unix Time Stamp
gettimeofday() Get Now's Unix Time Stamp
time() same as above, to get Unix Time Stamp
Convert Unix Time Stamp into Local Time Struct
Convert Time Struct into String
Convert Unix Time Stamp into String
The output is the same as asctime()
Custom Time format from time struct into String
Serial Output with formatted Time



Leave a comment

Your email address will not be published. Required fields are marked *

Please note, comments must be approved before they are published