pdf-icon

NTP

Obtain current time information from an NTP server.


import ntptime


#  Set NTP server
#  eg:
#  ntp = ntptime.client(host='jp.pool.ntp.org', timezone=8)
#  ntp = ntptime.client(host='sg.pool.ntp.org', timezone=8)
#  ntp = ntptime.client(host='tw.pool.ntp.org', timezone=8)
#  ntp = ntptime.client(host='hk.pool.ntp.org', timezone=8)
#  ntp = ntptime.client(host='tw.pool.ntp.org', timezone=8)
#  ntp = ntptime.client(host='hk.pool.ntp.org', timezone=8)
#  ntp = ntptime.client(host='us.pool.ntp.org', timezone=8)
#  ntp = ntptime.client(host='de.pool.ntp.org', timezone=8)

ntp = ntptime.client(host='cn.pool.ntp.org', timezone=8)

#  Get timestamp
ntp.getTimestamp()

#  Format date
ntp.formatDate('-')

#  Format time
ntp.formatTime('-')

#  Format date & time
ntp.formatDatetime('-', ':')

ntp.year()
ntp.month()
ntp.day()
ntp.hour()
ntp.minute()
ntp.second()
ntp.weekday()
On This Page