ESP32 FAQ

ESP32 RTC: Time, NTP, Real-Time Clock

// rtc · faq

Filed under: ESP32 · RTC · Updated August 2026

Does esp32 have rtc? Yes — but the interesting part is what it is not: not battery-backed, not a wall clock that survives power loss. Time on ESP32 is a mix of hardware, NTP, and knowing which board you have.

Does ESP32 Have RTC?

Yes — the ESP32 has a dedicated RTC peripheral with its own ultra-low-power 32 kHz oscillator, and it keeps ticking through deep sleep, which is how wake-from-sleep works and why time survives a nap. What it does not include is a battery input: cut all power and the clock forgets everything. So “does esp32 have rtc” covers the timer; the battery question is separate.

Does the ESP32 Have a Real Time Clock?

As a wall clock, sort of. While powered — or in deep sleep — it tracks seconds in RTC memory; on full power loss it’s back to epoch 0. Does the esp32 have a real time clock the way a DS3231 is one? No, there’s no coin cell on the die. If your device powers off and must remember the time, add an RTC module or re-sync from NTP on every boot.

Does ESP32 Have Built In Real Time Clock?

Built in: the RTC timer and RTC RAM. Not built in: the battery. Does esp32 have built in real time clock usually means “can I skip the DS3231” — and for anything connected to Wi-Fi, yes: NTP replaces the external chip entirely. For time that survives being unpowered, no module chip does that.

How to Get the Time with ESP32?

NTP, through the SNTP client in the Wi-Fi stack: configTime(gmtOffsetSec, daylightOffsetSec, “pool.ntp.org”); then time(nullptr) returns the epoch. Two lines, no library. How to get the time with esp32 offline is harder — you’re back to the drift question below. Call it in setup and re-sync periodically — the Wi-Fi FAQ has keep-alive details.

How to Print Time Using ESP32?

localtime() turns the epoch into a struct tm; strftime() formats it: strftime(buf, 32, “%Y-%m-%d %H:%M:%S”, &tm). How to print time using esp32 in local time vs UTC: gmtime() for UTC, and set the timezone before the first time() call — setenv(“TZ”, “CET-1CEST”, 1); tzset(); — or you’ll print GMT and call it local. That exact bug cost me an afternoon once.

How accurate is the RTC?

Typical modules drift 10–30 ppm — 1–2.5 seconds per day — depending on the oscillator. Fine for logs, wrong for anything on a schedule. My weather node re-syncs NTP every six hours and stays within a second a week. If there’s no Wi-Fi, the honest answer is a temperature-compensated chip like the DS3231.

Does time survive deep sleep?

Yes: RTC memory (RTC_DATA_ATTR variables) and the RTC timer both survive deep sleep. Store the last known epoch, wake up, add the slept seconds, done. Battery loggers use this pattern constantly — the power FAQ walks through the sleep budgets that make it work.

When do I need a battery-backed RTC module?

When the device powers off completely and must still know the time. The DS3231 is the accurate one, the PCF8523 the cheap one, the DS1307 the ancient one — all I2C, all take a CR2032, all work with the Wire library on SDA/SCL (GPIO21/22 on most devkits). A coin cell holds the clock for years — the one case where it beats NTP: no network.

Why does the ESP32 report the time as 1970?

Epoch 0 — the chip has no idea what time it is because NTP never succeeded. Check Wi-Fi first, then DNS, then whether configTime ran before your first time() call. Then timezone: time right in UTC, wrong in your prints. 1970 means no sync; the right hour on the wrong date means TZ.

Can I test time code before hardware arrives?

The strftime and timezone logic runs identically in the free ESP32 simulator, so formatting and offsets validate before the board arrives. The same sketch flashes straight across — the FAQ index has the rest of the setup path.

Read a Real-Time Clock — In Your Browser

Timekeeping over I2C, running live:

===========================
  DS1307 RTC Reader (I2C)
===========================
Time: 14:07:32
Time: 14:07:33

One tick per second, exactly as the register layout dictates — and if the chip does not answer, you are one bus scan away from knowing whether it is wiring or code. Compare the drift behavior with the NTP approach from this FAQ: the simulator shows you what a battery-backed clock does when Wi-Fi is nowhere in sight.

Leave a Reply

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