python获取本周日期范围
import datetime today = datetime.date.today() # 周一为第一天 week_start = today - datetime.timedelta(days=today.weekday()) week_end = today + datetime.timedelta(days=6-today.weekday()) print('week_start = {}\nweek_end = {}'.format(week_start,week_end)) # 周日为第一天 week_start = today - datetime.timedelta(days=today.weekday()+1) week_end = today + datetime.timedelta(days=6-today.weekday()-1) print('week_start = {}\nweek_end = {}'.format(week_start,week_end))
本文来自博客园,作者:OTAKU_nicole,转载请注明原文链接:https://www.cnblogs.com/nicole-zhang/p/16263688.html