关于时间

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%29%E2%80%9D%E6%96%B9%E5%BC%8F%E8%AE%A1%E7%AE%97%E5%87%BA%E5%90%8C%E4%B8%80%E5%A4%A9%E6%83%85%E5%BD%A2%E4%B8%8B%E7%9A%84%E6%97%B6%E9%97%B4%E5%B7%AE%E6%88%96%E8%80%85%E4%B8%8D%E5%90%8C%E5%A4%A9%E7%9A%84%E6%97%B6%E9%97%B4%E5%B7%AE%E5%8D%B3%E5%8F%AF%E3%80%82%20%E6%9C%AC%E6%96%87%E6%93%8D%E4%BD%9C%E7%8E%AF%E5%A2%83%EF%BC%9Awindows7%E7%B3%BB%E7%BB%9F%E3%80%81python2.7.14%E7%89%88%EF%BC%8CDELL%20G3%E7%94%B5%E8%84%91%E3%80%82

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