linux date hwclock

import httplib   
import time
import os
def get_webservertime(host):
conn=httplib.HTTPConnection(host)
conn.request("GET", "/")
r=conn.getresponse()
ts=r.getheader('date')
ltime=time.strptime(ts[5:25], "%d %b %Y %H:%M:%S")
print(ltime)
ttime=time.localtime(time.mktime(ltime)+8*60*60)
print(ttime)


dat2="date -s %2u/%02u/%u"%(ttime.tm_mon,ttime.tm_mday,ttime.tm_year,)
tm2="date -s %02u:%02u:%02u"%(ttime.tm_hour,ttime.tm_min,ttime.tm_sec)
print (dat,tm)
os.system(dat2)
os.system(tm2)


get_webservertime('www.baidu.com')

你可能感兴趣的:(linux date hwclock)