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

大家讲道理
Release: 2016-11-09 10:51:15
Original
2337 people have browsed it

[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
Copy after login


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template