发布时间:2019-09-05 07:33:58编辑:auto阅读(1765)
import httplib
import time
import os
def get_webservertime(host):
try:
conn=httplib.HTTPConnection(host)
conn.request("GET", "/")
r=conn.getresponse()
#r.getheaders() #获取所有的http头
ts= r.getheader('date') #获取http头date部分
print '============================'
print ts
print '============================'
#将GMT时间转换成北京时间
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)
dat="date %u-%02u-%02u"%(ttime.tm_year,ttime.tm_mon,ttime.tm_mday)
tm="time %02u:%02u:%02u"%(ttime.tm_hour,ttime.tm_min,ttime.tm_sec)
currenttime="%u-%02u-%02u %02u:%02u:%02u"%(ttime.tm_year,ttime.tm_mon,ttime.tm_mday,ttime.tm_hour,ttime.tm_min,ttime.tm_sec)
print currenttime
print (dat,tm)
os.system(dat)
os.system(tm)
except:
return False
get_webservertime('www.baidu.com')
上一篇: Python中的栈
下一篇: python socks5 proxy实
47863
46424
37314
34761
29332
25990
24945
19967
19564
18050
5806°
6433°
5949°
5975°
7080°
5926°
5963°
6456°
6418°
7798°