1、获取秒级时间戳与毫秒级时间戳
import time import datetime t = time.time() print (t) #原始时间数据 print (int(t)) #秒级时间戳 print (int(round(t * 1000))) #毫秒级时间戳 nowTime = lambda:int(round(t * 1000)) print (nowTime()); #毫秒级时间戳,基于lambda print (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) #日期格式化
返回
1499825149.26 1499825149 1499825149257 1499825149257 2017-07-12 10:05:49
2、将日期转为秒级时间戳
strf_time = '2018-01-01 10:40:30' time_stamp = int(time.mktime(time.strptime(strf_time, "%Y-%m-%d %H:%M:%S"))) print (time_stamp)
返回
1514774430
3、将秒级时间戳转为日期
time_stamp = 1528962798 strf_time = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.localtime(timestamp)) print(strf_time)
返回
'2018-05-22T11:00:00Z'