Python uses the ntplib library to synchronously calibrate the local time, pythonntplib
Network Time Protocol was proposed by Professor David L. Mills of the University of Drava in 1985 to design a Protocol for enabling different machines to maintain the same Time on the Internet.
NTP estimates the round-trip latency of packets on the network and independently estimates the Computer Clock Deviation, so as to achieve high precision during computer calibration on the network.
NTP is common in Linux systems. In fact, Python is the same. When you can search for "python get time" on the Internet, many of them are stupid ways to parse the page get time, python can also use the NTP service for time synchronization to obtain the exact time. You only need to use the ntplib library.
Usage of ntplib Library
Install ntplib:
Easy_install ntplib
Or
Pip install ntplib
The code below.
Import OS import time import ntplib c = ntplib. NTPClient () response = c. request ('pool .ntp.org ') ts = response. tx_time _ date = time. strftime ('% Y-% m-% d', time. localtime (ts) _ time = time. strftime ('% x', time. localtime (ts) OS. system ('date {}& & time {}'. format (_ date, _ time ))
In this way, you can easily synchronize local time ~