Python获取前N周时间开始日期和截止日期

import datetime


today = datetime.datetime.today().date()
print today.weekday()
for i in range(10):
    next_week_start = today + datetime.timedelta(days=today.weekday() - 15 - 7 * i)
    next_week_end = today + datetime.timedelta(days=today.weekday() - 9 - 7 * i)
    print next_week_start, next_week_end

 

4
2019-08-26 2019-09-01
2019-08-19 2019-08-25
2019-08-12 2019-08-18
2019-08-05 2019-08-11
2019-07-29 2019-08-04
2019-07-22 2019-07-28
2019-07-15 2019-07-21
2019-07-08 2019-07-14
2019-07-01 2019-07-07
2019-06-24 2019-06-30

Process finished with exit code 0

 后N周时间同理。 

posted @ 2019-09-06 11:31  青花メ  阅读(1469)  评论(0编辑  收藏  举报