在最近的开发需求中涉及到获取特定日期(年月日格式)
例如,2nd week of July---获取2022年7月份第二周的日期(7月第2个星期一)
import calendar
c = calendar.Calendar(firstweekday=calendar.SUNDAY)
year = 2022
month = 7
monthcal = c.monthdatescalendar(year,month)
# sencond_monday返回date类型——2022-07-11
second_monday = [day for week in monthcal for day in week if \
day.weekday() == calendar.MONDAY and \
day.month == month][1]
second_monday:2022-07-11