python获取上一个月的天数

[python]代码

#简单小程序
from datetime import datetime
import calendar
def getmonths():
d = datetime.now()
c = calendar.calendar()
year = d.year
month = d.month
if month == 1 :
month = 12
year -= 1
else :
month -= 1
months = calendar.monthrange(year, month)[1]
return months

Posted in 未分类

发表评论