Home >Backend Development >Python Tutorial >Python gets the number of days in the previous month

Python gets the number of days in the previous month

大家讲道理
大家讲道理Original
2016-11-09 10:51:152340browse

[Python] Code

#简单小程序
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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn