# -*- coding:utf-8 -*-
from setting import *
import datetime
sys.path.append(LIB_DIR)
# print(LIB_DIR)
class TimeFormat:
'''格式化时间'''
def now_time(self, format):
'''
当前时间
:param format: 时间戳格式
:return: 返回当前时间
'''
try:
return datetime.datetime.now().strftime(format)
except Exception as e:
return e
def n_days_later(self, n, format):
'''
n天后的时间
:param n: 天数
:param format: 时间戳格式
:return: 返回n天后的时间
'''
try:
time = (datetime.datetime.now() + datetime.timedelta(days=n)).strftime(format)
return time
except Exception as e:
return e
def n_hours_later(self, n, format):
'''
n小时后的时间
:param n: 小时数
:param format:
:return:
'''
try:
time = (datetime.datetime.now() + datetime.timedelta(hours=n)).strftime(format)
return time
except Exception as e:
return e
def n_minutes_later(self, n, format):
'''
n分钟后的时间
:param n: 分钟
:param format:
:return:
'''
try:
time = (datetime.datetime.now() + datetime.timedelta(minutes=n)).strftime(format)
return time
except Exception as e:
return e
if __name__ == '__main__':
t = TimeFormat()
s = t.now_time("%Y-%m-%d %H:%M:%S")
l = t.n_hours_later(n=100, format="%Y-%m-%d %H:%M:%S")
print(s)
print(l)