.. _ntptime: :mod:`ntptime` --- Time synchronization ========================================= .. module:: ntptime This module is used for time synchronization and provides accurate time, International Standard Time (UTC). .. admonition:: What is NTP Network Time Protocol (NTP) is a protocol used to synchronize computer clocks. It allows a computer to synchronize with its server or clock source (such as a quartz clock, GPS, etc.). It can provide high-precision time correction. Methods ------- .. method:: settime(timezone=8,server = 'ntp.ntsc.ac.cn') Synchronize the local time. - ``timezone`` - the time zone offset, defaulting to UTC+8, compensating by 8 hours - ``server`` - you can specify your own time server; server is a string type. The default time server is "ntp.ntsc.ac.cn". Example:: from mpython import * import ntptime mywifi=wifi() mywifi.connectWiFi('tang','tang123456') print("Local time before sync: %s" %str(time.localtime())) ntptime.settime() print("Local time after sync: %s" %str(time.localtime())) Result:: Connecting to network... WiFi Connection Successful,Network Config:('172.20.10.4', '255.255.255.240', '172.20.10.1', '172.20.10.1') Local time before sync: (2000, 1, 1, 0, 40, 8, 5, 1) Local time after sync: (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. >>>