import copy
import calendar
from dateutil.relativedelta import relativedelta
def get_time_list():
time_create = '2018-10-01 00:00:00' # TODO
time_distance = '2018-10-31 23:59:59' # TODO
time_end = '2019-08-31 23:59:59'
start = datetime.datetime.strptime(time_create, "%Y-%m-%d %H:%M:%S")
delatime = datetime.datetime.strptime(time_distance, "%Y-%m-%d %H:%M:%S")
end_time = datetime.datetime.strptime(time_end, "%Y-%m-%d %H:%M:%S")
time_list = [[start, delatime]]
while start < end_time:
start += relativedelta(months=1)
delatime += relativedelta(months=1)
end = start + datetime.timedelta(days=calendar.monthrange(start.year, start.month)[1] - 1, hours=23, minutes=59,seconds=59)
end = copy.deepcopy(end)
time_list.append([start, end])
res = time_list[:-2]
# print(res)
return res
def get_week_time_list(start, end):
week_time = list()
temp = start
for _ in range(4):
start += datetime.timedelta(days=7)
if (end - start).days < 5:
start = end
week_time.append([temp, start])
temp = start
# print(week_time)
return week_time
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有