关于时间

import time
import datetime
t = datetime.datetime.now()
time_now =t.strftime('%Y-%m-%d %H:%M:%S')    # 获取现在时间 如:2022-09-19 17:33:41

time_before = (t-datetime.timedelta(minutes=10)).strftime("%Y-%m-%d %H:%M:%S")    # 获取十分钟前的时间
stime = int(time.mktime(time.strptime(time_now,'%Y-%m-%d %H:%M:%S')))    # 获取时间戳秒级时间戳
etime = int(time.mktime(time.strptime(time_before,'%Y-%m-%d %H:%M:%S')))    # 获取十分钟前的秒级时间戳

t = time.time()
time_s = int(round(t * 1000))    # 获取毫秒级时间戳

times = time.time()
gmtimes = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(times))    # 获取格林威治时间

详细计算:
https://blog.csdn.net/weixin_39773337/article/details/113871151
https://www.php.cn/python-tutorials-471326.html#:~:text=python计算时间差的方法:首先引入datetime包;然后通过“ (time_2_struct -,time_1_struct)”方式计算出同一天情形下的时间差或者不同天的时间差即可。 本文操作环境:windows7系统、python2.7.14版,DELL G3电脑。

posted @ 2022-09-19 17:45  vetra  阅读(49)  评论(0)    收藏  举报