6.5.9. boing.net.ntp — NTP utilities

The module boing.net.ntp provides few functions for handling the Network Time Protocol (NTP).

Example:

import datetime
from boing.net import ntp
srvtime = ntp.ntpFromServer("europe.pool.ntp.org")
srvdatetime = ntp.ntp2datetime(srvtime)
now = datetime.datetime.now()
print("Server time:", srvdatetime)
print("Local time:", now)
print("Delta:", now - srvdatetime)
boing.net.ntp.ntpEncode(t)

Return the bytes object obtained from encoding the POSIX timestamp t.

boing.net.ntp.ntpDecode(data)

Return the POSIX timestamp obtained from decoding the bytes object data.

boing.net.ntp.ntpFromServer(server)

Send an ntp time query to the server and return the obtained POSIX timestamp. The request is sent by using an UDP connection to the port 123 of the NTP server.

boing.net.ntp.ntp2datetime(t)

Return the datetime.datetime instance corresponding to the POSIX timestamp t.

boing.net.ntp.datetime2ntp(dt)

Return the POSIX timestamp corresponding to the datetime.datetime instance dt.

Previous topic

6.5.8. boing.net.udp — UDP utilities

Next topic

6.6. boing.nodes — The nodes of the pipeline