#coding=utf-8 import time import datetime t=datetime.datetime.now() #当前日期 t1 =t.strftime('%Y-%m-%d 00:00:00') #转为秒级时间戳 start_time=time.mktime(time.strptime(t1, '%Y-%m-%d %H:%M:%S')) #转为毫秒级 print(str(start_time*1000).split(".")[0]) #30天后 t2=(t+datetime.timedelta(days=30)).strftime("%Y-%m-%d 00:00:00") #转为秒级时间戳 end_time=time.mktime(time.strptime(t2, '%Y-%m-%d %H:%M:%S')) #转为毫秒级 print(str(end_time*1000).split(".")[0])
输出
localhost:Desktop macname$ python3 test_time.py 1575561600000 1578153600000
参考:
https://www.cnblogs.com/strivepy/p/10436213.html
https://www.cnblogs.com/jfl-xx/p/8024596.html
https://www.runoob.com/python/func-number-choice.html
https://www.cnblogs.com/vampirejt/p/4159267.html
https://blog.csdn.net/asher117/article/details/83012803