python 获取每个月的最后一天或者获取每个月有多少天

python calendar库monthrange函数可以返回指定月份的最后一天

1 import calendar
2 lastDay = calendar.monthrange(2022,2)[1]
3 #返回28
4 lastDay2 = calendar.monthrange(2024,2)[1]
5 #返回29

 

posted @ 2022-07-17 18:44  司徒韵然  阅读(732)  评论(0)    收藏  举报