多个个月前
arrow.get(end_time_str, 'YYYY-MM-DD HH:mm:ss').shift(months=-6).format('YYYY-MM-DD HH:mm:ss')
获取几小时之前,几分钟前,几天前,几个月前,及几年前的具体时间
import datetime
import arrow
def getTime(self, flag,dayhourminute):
'''
获取几小时之前,几分钟前,几天前,几个月前,及几年前的具体时间 flag, 1:天;2:小时;3:分钟;4:月,5:年
:param flag: 1:天;2:小时;3:分钟;4:月,5:年
:param dayhourminute: 整数值
:return: 具体时间 %Y-%m-%d %H:%M:%S
'''
tn = datetime.datetime.now()
t = None
ttime =''
if flag <= 1:
if flag == 1:
t = datetime.timedelta(days=dayhourminute)
elif flag == 2:
t = datetime.timedelta(hours=dayhourminute)
elif flag == 3:
t = datetime.timedelta(minutes=dayhourminute)
strtime = tn - t
ttime = strtime.strftime('%Y-%m-%d %H:%M:%S')
else:
dt = arrow.now()
if flag == 4:
ttime = dt.shift(months=-dayhourminute).format("YYYY-MM-DD HH:MM:SS")
elif flag == 5:
ttime = str(int(datetime.datetime.now().strftime("%Y"))-dayhourminute)+"-"+datetime.datetime.now().strftime("%m-%d")
return ttime
标签:arrow,ss,每日,HH,datetime,flag,模块,DD
From: https://www.cnblogs.com/sunxiuwen/p/17269417.html