格式返回:2000-12-13 18:58
import datetime
import time
class Time:
def minute(self, add_minute=0,now_time=False):
"""
返回年月日 时分
:param add_minute: 分钟可加可减
:return:
"""
if now_time:
year_month_day_hour_minute = now_time
else:
year_month_day_hour_minute = time.strftime('%Y-%m-%d %H:%M', time.localtime(time.time()))
minute = year_month_day_hour_minute[14:16]
minute_total = add_minute + int(minute)
multiple = minute_total // 60
# 要返回的时间属于 过去至最近1小时
if minute_total < -60:
year_month_day_hour = self.hour(multiple)
minute = self.__format_processing(abs(minute_total % 60), val=2)
return year_month_day_hour + minute
# 要返回的时间属于最近过去的1小时
elif -60 <= minute_total <= 0:
if minute_total == 0:
year_month_day_hour = self.hour(0)
minute = ':00'
else:
year_month_day_hour = self.hour(-1)
minute = self.__format_processing(str(minute_total + 60), val=2)
return year_month_day_hour + minute
# 要返回的时间属于当前1小时
elif 0 < minute_total <= 60:
if minute_total == 60:
return self.hour(1) + ':00'
else:
return year_month_day_hour_minute[0:13] + self.__format_processing(minute_total, val=2)
# 要返回的时间属于未来1小时以后
elif 60 < minute_total:
year_month_day = self.hour(multiple)
minute = self.__format_processing(minute_total % 60, val=2)
return year_month_day + minute