1 转换时区utc比北京时间慢八个小时
from datetime import tzinfo, timedelta, datetime ZERO = timedelta(0) class UTC(tzinfo): def utcoffset(self, dt): return ZERO def tzname(self, dt): return "UTC" def dst(self, dt): return ZERO utc = UTC()
2 导入当前时间
import datetime end_time=datetime.datetime.now(utc) # utc 转换时区相加减
2.1 将当前时间往前推迟24小时
import datetime start_time=datetime.datetime.now(utc)+datetime.timedelta(hours=-24)
3 将时间差转换为秒
time_data = end_time - (i.approve_ts) # time = time_data.seconds + time_data.days * 24 * 3600 # 将时间差转换成秒