最近要开发一款抢购秒杀的小工具,需要同步系统时间,这里分享两个时间服务器接口api给大家:
1.淘宝时间服务器时间接口
http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp
返回json数据
{"api":"mtop.common.getTimestamp","v":"*","ret":["SUCCESS::接口调用成功"],"data":{"t":"1586519130440"}}
Python获取淘宝时间服务器时间示例
1 import requests 2 import time 3 4 class timeTaobao(object): 5 r1 = requests.get(url='http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp', 6 headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36'}) 7 x = eval(r1.text) 8 timeNum = int(x['data']['t']) 9 10 def funcname(): 11 timeStamp = float(timeTaobao.timeNum/1000) 12 timeArray = time.localtime(timeStamp) 13 otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) 14 return otherStyleTime 15 16 t = timeTaobao.funcname() 17 print(t)
2.苏宁时间服务器接口api:
http://quan.suning.com/getSysTime.do
返回json数据
{"sysTime2":"2020-04-10 19:46:50","sysTime1":"20200410194650"}