获取当前时间的前(后)N天
def get_days_before_today(n=0):
'''''
date format = "YYYY-MM-DD HH:MM:SS"
'''
now = datetime.datetime.now()
if(n<0):
return datetime.datetime(now.year, now.month, now.day, now.hour, now.minute, now.second)
else:
n_days_before = now - timedelta(days=n)
return datetime.datetime(n_days_before.year, n_days_before.month, n_days_before.day, n_days_before.hour, n_days_before.minute, n_days_before.second)
获取当前时间的前(后)N周
def get_weeks_before_tody(n=0):
'''''
date format = "YYYY-MM-DD HH:MM:SS"
'''
now = datetime.datetime.now()
if(n<0):
return datetime.datetime(now.year, now.month, now.day, now.hour, now.minute, now.second)
else:
n_days_before = now - tim