The NTP Network Time Protocol can be accessed more or less at ordinary times. many Internet time synchronization functions in operating systems, including Windows, are implemented based on NTP, here, let's take a look at Python's method of synchronizing calibration of local Time using the ntplib Library NTP (Network Time Protocol) is by David L of the University of Drava. professor Mills proposed in 1985 that a communication protocol was designed to allow 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 ~