Python获取周日周一
可返回sunday或monday
from datetime import datetime
from datetime import timedelta
from datetime import date
def get_sunday(weekly):
"""
获取指定日期的周一和周日日期
weekly: weekly=0当前周,1下一周,-1上一周
"""
today = date.today()
last = weekly * 7
today = datetime.strptime(str(today),"%Y-%m-%d")
monday = datetime.strftime(today - timedelta(today.weekday() - last), "%Y-%m-%d")
monday_ = datetime.strptime(monday, "%Y-%m-%d")
sunday = datetime.strftime(monday_ + timedelta(monday_.weekday() + 6), "%Y-%m-%d")
return sunday