京东时间同步
import requestsimport time
import json
import win32api
def jd_time():
url = 'https://a.jd.com//ajax/queryServerData.html'
ret = requests.get(url).text
# json格式的获取文本
jd_t=json.loads(ret)
# 是个字典,要先读取字典的值,然后再做浮点数转换
jd_time_stamp=float(jd_t["serverTime"])/1000
# 时间戳转换
jd_time_stamp=time.localtime(jd_time_stamp)
return(jd_time_stamp)
def settime():
tt = time.localtime(time.mktime(jd_time()) - 8 * 60 * 60)
win32api.SetSystemTime(tt.tm_year, tt.tm_mon, tt.tm_wday, tt.tm_mday, tt.tm_hour, tt.tm_min, tt.tm_sec, tt.tm_isdst)
print "京东时间同步成功"
settime()
页:
[1]