The ESP32 has a real time clock implemented on chip. This will however only work as long as the ESP32 is powered. It may therefore be interesting to employ an external RTC like the DS1307, backed up with a battery, to keep time even when the ESP32 is powered off or in deep sleep mode.