ntptime — Time synchronization

This module is used for time synchronization, providing accurate time, International Standard Time (UTC).

what is NTP

Network Time Protocol (NTP) is a protocol used to synchronize the time of the computer. It can synchronize the computer to its server or clock source (such as quartz clock, GPS, etc.). It can provide highly precise time calibration.


ntptime.settime(timezone=8, server = 'ntp.ntsc.ac.cn')

Synchronize local time

  • timezone - Time zone time difference, the default is East Eight District, compensation 8 hours
  • server - You can specify the time server yourself, server is a string type. The default time server is “ntp.ntsc.ac.cn” .


from mpython import *
import ntptime


print("Local time before synchronization:%s" %str(time.localtime()))
print("Local time after synchronization:%s" %str(time.localtime()))


Connecting to network...
WiFi Connection Successful,Network Config:('', '', '', '')
Local time before synchronization:(2000, 1, 1, 0, 40, 8, 5, 1)
Local time after synchronization:(2018, 12, 27, 12, 10, 7, 3, 361)
MicroPython v1.0.1-dirty on 2018-11-23; mPython with ESP32
Type "help()" for more information.