# -*- coding: utf-8 -*-
# @Time : 18-10-8 下午5:53
# @Author : Felix Wang
import time
def get_day_of_day(UTC=False, days=0, hours=0, miutes=0, seconds=0, date=None):
'''
if days >= 0, date is larger than today
if days < 0, date is less than today
date format = "YYYY-MM-DD"
'''
if not date:
now = time.time()
else:
now = time.mktime(time.strptime(date, '%Y-%m-%d %H:%M:%S'))
UTC = False
timeNew = now + days * 24 * 60 * 60 + hours * 60 * 60 + miutes * 60 + seconds
if UTC:
timeNew = timeNew + time.timezone
t = time.localtime(timeNew)
return time.strftime('%Y-%m-%d %H:%M:%S', t)
# 自定义时间,1天120秒后的时间
t = get_day_of_day(date='2018-02-28 23:58:00', days=1,seconds=120)
print(t)
# 使用UTC时间 两小时前
t = get_day_of_day(True, 0, -2)
print(t)
# 当地时间 三天前
t = get_day_of_day(False, -3)
print(t)
# 当地时间 三天后
t = get_day_of_day(False, 3)
print(t)