【python】查询当前日期的所在月的天数

发布时间 2023-07-18 14:17:05作者: Phoenixy

查询当前日期的所在月的天数

# coding:utf-8
import datetime
import calendar
from loguru import logger as logs


class ca:

    @staticmethod
    def days_of_the_month():
        """查询当前日期的所在月的天数"""

        # cur_date = datetime.datetime.strptime(cur_date, "%Y%m%d")
        cur_date = datetime.datetime.now()
        year = cur_date.year
        month = cur_date.month
        logs.debug(cur_date.strftime("%Y%m%d"))
        init_days_weekday, month_last_day = calendar.monthrange(year, month)  # a,b——weekday的第一天是星期几(0-6对应星期一到星期天)和这个月的所有天数
        logs.debug("这个月的所有天数:{}".format(month_last_day))
        return month_last_day


if __name__ == "__main__":
    """ Run """

    """当月天数"""
    ca.days_of_the_month()

 

执行结果: