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

相关文章:

  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2021-10-21
  • 2022-01-08
  • 2022-01-15
  • 2021-12-02
  • 2021-09-10
猜你喜欢
  • 2021-10-30
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
相关资源
相似解决方案