一、獲取秒級時間戳與毫秒級時間戳html
import time
import datetimepython
t = time.time()ide
print (t) #原始時間數據
print (int(t)) #秒級時間戳
print (int(round(t * 1000))) #毫秒級時間戳htm
nowTime = lambda:int(round(t * 1000))
print (nowTime()); #毫秒級時間戳,基於lambdablog
print (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) #日期格式化get
返回it
1499825149.26
1499825149
1499825149257
1499825149257
2017-07-12 10:05:49class
二、將日期轉爲秒級時間戳import
dt = '2018-01-01 10:40:30'
ts = int(time.mktime(time.strptime(dt, "%Y-%m-%d %H:%M:%S")))
print (ts)lambda
返回
1514774430
三、將秒級時間戳轉爲日期
ts = 1515774430
dt = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts))
print(dt)
返回
2018-01-13 00:27:10