Source: https://mokxi.com/libraries/eztime
Updated: 2026-11-23

Libraries / Data and time

Arduino library · Data and time

# ezTime: the time in any time zone, daylight saving included

Yes, with limits. You can use the ezTime library online in Mokxi with nothing to install, and the sketch runs in your browser. Part of it is not simulated, and the notes below say which. The example below, "The time in UTC, Berlin and Auckland", runs on the ESP32-C3-DevKitM-1.

Run the example in Mokxi See the calls

Built in on Mokxi: #include <ezTime.h> and it builds, with nothing to install. Free, and no account needed.

## What ezTime does

ezTime, by Rop Gonggrijp, is a time library for the ESP32 and ESP8266 that does three jobs in one: it syncs the clock over NTP, it knows time zones and their daylight saving rules, and it formats dates the way PHP’s date() does. Where NTPClient leaves you with a fixed offset and TimeLib with no time zones at all, ezTime gives you "Berlin at 14:00 CEST" in two lines.

waitForSync() blocks until the first NTP answer arrives. The built-in UTC object is always ready; for a local zone you make a Timezone and either call setLocation("Europe/Berlin"), which asks ezTime’s own lookup server for the rules, or setPosix() with a rule string such as "CET-1CEST,M3.5.0,M10.5.0/3", which needs no lookup. dateTime() then formats with letters like H, i, l and T.

In Mokxi NTP and the location lookup are UDP, which the simulated network does not carry. waitForSync() sets the clock from the simulation’s own, which starts at 2026-01-01 00:00:00 UTC, setLocation() knows about two dozen common place names itself, and setPosix() takes any zone. The example prints UTC, Berlin and Auckland, and Berlin in July with summer time applied.

Library Manager name | ezTime

Author | Rop Gonggrijp

Include | #include <ezTime.h>

Boards | ESP32-C3, ESP32-C6, Seeed XIAO ESP32-C3, ESP32-C3 SuperMini, Seeed XIAO ESP32-C6, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32, ESP32-S3-CAM, ESP8266 NodeMCU

In the simulator | Runs, with a gap the note below names.

## Install it

It builds on ESP32-C3, ESP32-C6, Seeed XIAO ESP32-C3, ESP32-C3 SuperMini, Seeed XIAO ESP32-C6, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32, ESP32-S3-CAM, ESP8266 NodeMCU.

In Mokxi it is built in: #include <ezTime.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "ezTime" by Rop Gonggrijp from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add ezTime to lib_deps in PlatformIO. Mokxi follows the calls of release 0.8.3, so a sketch written here builds there too.

What to know in the simulator: NTP and the place-name lookup run over UDP, which the simulated network does not carry: waitForSync() sets the clock from the simulation’s own, which starts at 2026-01-01 00:00:00 UTC, and setLocation() knows two dozen common place names itself (setPosix() takes any zone). Daylight saving follows the POSIX rule.

- ESP32-C3
- ESP32-C6
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32 DevKit
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- ESP32-S3-DevKitC-1
- Seeed XIAO ESP32-S3
- Arduino Nano ESP32
- ESP32-S3-CAM
- ESP8266 NodeMCU

## The calls you will use

In the order a sketch meets them.

### waitForSync()

Waits for the first NTP sync and returns true when it arrives. Pass a number of seconds to stop waiting after that long.

### Timezone Berlin

A time zone object. Until you set a location or a POSIX rule it behaves like UTC.

### Berlin.setLocation("Europe/Berlin")

Loads the zone’s rules by its Olson name from ezTime’s lookup server. Returns false on failure; errorString() says why.

### Berlin.setPosix("CET-1CEST,M3.5.0,M10.5.0/3")

Sets the zone from a POSIX rule with no network lookup. The sign is reversed: CET-1 means one hour ahead of UTC.

### Berlin.dateTime("l, d-M-Y H:i:s T")

Formats the local time with PHP date() letters, here like "Thursday, 01-Jan-2026 01:00:00 CET". UTC.dateTime(ISO8601) gives the standard form.

### makeTime(12, 0, 0, 1, 7, 2026)

Builds a time_t from hour, minute, second, day, month and year, to format or compare a moment other than now.

### events()

Runs ezTime’s housekeeping: periodic NTP resyncs and any events you set. Call it on every pass of loop().

### minuteChanged()

True once at the start of each new minute, an easy way to refresh a clock display without a timer.

## Example: The time in UTC, Berlin and Auckland

On the ESP32-C3-DevKitM-1. It runs in the browser exactly as printed.

sketch.ino · ESP32-C3-DevKitM-1

Open it in the editor, wired and ready to run

## Common errors and how to fix them

### setLocation() returns false and errorString() says "Timeout" or "Data not found"

The lookup server did not answer or does not know that name. Check the spelling of the Olson name, such as America/New_York, or skip the lookup with setPosix() and a rule string, which works offline and on every restart.

### The local time is right in winter and an hour off in summer

The zone was set with a plain offset or a POSIX string without the daylight saving part. Use the full rule, for example "EST5EDT,M3.2.0,M11.1.0" for New York, or setLocation(), so ezTime applies the change on its own.

### The clock drifts or never resyncs after a day

events() is not called, so ezTime never gets the chance to resync over NTP. Add events() to loop(), and keep loop() free of long blocking code.

## Questions and answers

### ezTime or the Timezone library?

The Timezone library converts UTC to local time with rules you write in code, and you supply the time from somewhere else. ezTime gets the time itself and can look rules up by city name, but runs only on network boards.

## Keep going

### Learn

- Arduino millis(): Timers and Multiple Tasks
- ESP32 Not Connecting to WiFi: Causes and Fixes

### More data and time libraries

- QRCode
- Madgwick
- PID
- TimerOne
- MsTimer2
- Low-Power
- RTClib
- DS1307RTC
- Ds1302
- Chrono
- Tasker
- CountDown
- microDS3231
- DS1307 (Seeed)

Every built-in library · Open the editor

## Try ezTime without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
