NTP (Network time Protocol) was proposed in 1985 by Professor David L. Mills of the University of the United States to design a communication protocol designed to enable 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 bias to achieve high precision computer school on the network.
NTP service in Linux system is more common, in fact, Python is the same, can be online search "Python acquisition Time", many are the stupid way to parse the page to get time, but Python can also use NTP services to achieve time synchronization to obtain accurate time, You only need to use the Ntplib library to implement it.
Introduction to Ntplib Library usage
Install Ntplib:
Or
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))
This will make it easy to sync local time.