Home Documentation Tutorials API GitHub

NTP

The Ntpd daemon provides support for synchronizing wall clock time using the NTP protocol.

Ntpd

To use NTP simply start the daemon using start, synchronization will begin in the background:

Ntpd().start

To block your application until a valid time has been acquired, first setup your network interface, then call sync to wait:

// start and setup network
Networkd().start
Networkd.cur.setup(["name":"eth0", "mode":"dhcp"])

// setup network interface, and block until NTP acquires time
Ntpd().start
Ntpd.cur.sync

echo("Time is $DateTime.now")

An optional timeout may be passed to sync, where the method returns true if time was successfully acquired, or false if it timed out:

if (Ntpd.cur.sync(30sec)) echo("Time is $DateTime.now")
else echo("Sync timed out")