在最近的开发需求中涉及到获取特定日期(年月日格式)
例如,2nd week of July---获取2022年7月份第二周的日期(7月第2个星期一)
复制代码
1
2
3
4
5
6
7
8
9import 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
最后
以上就是聪明小懒虫最近收集整理的关于[Work Summary] Python获取每月特定日期的全部内容,更多相关[Work内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复