获取特定服务器时间(格式:毫秒级 微秒级)注意显示格式
def get_web_now_timea(time_format='YYYY-MM-DD HH:mm:ss.SSSSSS'): """ 获取网络时间,返回时间格式:2019-12-13 11:39:48.398 :param time_format:控制返回字符串的格式,默认为:'YYYY-MM-DD HH:mm:ss.SSS' :return: """ import arrow as ar import requests as req #print('\n========= 获取网络时间 =========') try: res = req.get('http://shop.jsanycall.cn/').headers['Date'] # res = req.get('https://www.hao123.com/').headers['Date'] time_diff = ar.get(res[4:-4], 'DD MMM YYYY HH:mm:ss') - ar.now().floor('second') web_now_time = (ar.now() + time_diff).format(time_format) #print('web_now_time={}'.format(web_now_time)) return web_now_time except BaseException as e: print('获取网络时间出错,出错原因:{}'.format(e)) return -1
2022-03-20 09:29:46.379016
>>
def get_web_now_timea(time_format='YYYY-MM-DD HH:mm:ss.SSS'): """ 获取网络时间,返回时间格式:2019-12-13 11:39:48.398 :param time_format:控制返回字符串的格式,默认为:'YYYY-MM-DD HH:mm:ss.SSS' :return: """ import arrow as ar import requests as req #print('\n========= 获取网络时间 =========') try: res = req.get('http://shop.jsanycall.cn/').headers['Date'] # res = req.get('https://www.hao123.com/').headers['Date'] time_diff = ar.get(res[4:-4], 'DD MMM YYYY HH:mm:ss') - ar.now().floor('second') web_now_time = (ar.now() + time_diff).format(time_format) #print('web_now_time={}'.format(web_now_time)) return web_now_time except BaseException as e: print('获取网络时间出错,出错原因:{}'.format(e)) return -1
2022-03-20 09:30:54.349
>>>