"""
自动生成时间的脚本
"""
import datetime
class CreateTine(object):
# 或者当年时间
now_time = datetime.date.today()
@staticmethod
def year_month_day(start, end):
"""
生成年月日
:param start_time: 起始时间 eg: "2020-06-11"
:param end_time: 结束时间默认为当前时间
:return:
"""
start_time = start.split("-")
end_time = str(end).split("-")
day_num = (datetime.datetime(int(end_time[0]), int(end_time[1]), int(end_time[2])) - datetime.datetime(
int(start_time[0]), int(start_time[1]), int(start_time[2]))).days
start_datetime = datetime.datetime.strptime(start, '%Y-%m-%d')
return [str(start_datetime + datetime.timedelta(days=i))[:10] for i in range(day_num + 1)]
@staticmethod
def hour_minute_second(n):
second = 87400
second_list = list(range(100, second, int(second / n)))
for seconds in second_list:
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
yield "%d:%02d:%02d" % (h, m, s)
@staticmethod
def create_date(start_time, n, end_time=now_time):
year_month_day_list = list(CreateTine.year_month_day(start_time, end_time))
hour_minute_second_list = list(CreateTine.hour_minute_second(n))
for year_month_day in year_month_day_list:
for hour_minute_second in hour_minute_second_list:
yield year_month_day + " " + hour_minute_second
if __name__ == '__main__':
x = CreateTine.create_date('2019-08-31',10)
print(list(x))
# l = list(CreateTine.hour_minute_second(50000))
# print(l)