import time
import datetime
t=datetime.datetime.now()
#当前日期
t1 =t.strftime('%Y-%m-%d %H:%M:%S')
#转为秒级时间戳
ts1=time.mktime(time.strptime(t1, '%Y-%m-%d %H:%M:%S'))
#转为毫秒级
end_time=int(str(ts1*1000).split(".")[0])
#1小时前
t2=(t-datetime.timedelta(hours=1)).strftime("%Y-%m-%d %H:%M:%S")
#转为秒级时间戳
ts2=time.mktime(time.strptime(t2, '%Y-%m-%d %H:%M:%S'))
#转为毫秒级
start_time=int(str(ts2*1000).split(".")[0])
print("
","*"*30)
print(start_time)
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts2)))
print("*"*30)
print(end_time)
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts1)))
print("*"*30,"
")
转载自:https://www.cnblogs.com/sea-stream/p/12183018.html