编程语言
首页 > 编程语言> > python获取某一年的所有节假日

python获取某一年的所有节假日

作者:互联网

import datetime
import chinese_calendar


def get_holidays(year=None, include_weekends=True):
    """
    获取某一年的所有节假日,默认当年
    :param year: which year
    :param include_weekends: False for excluding Saturdays and Sundays
    :return: list
    """
    if not year:
        year = datetime.datetime.now().year
    else:
        year = year
    start = datetime.date(year, 1, 1)
    end = datetime.date(year, 12, 31)
    holidays = chinese_calendar.get_holidays(start, end, include_weekends)
    return holidays

标签:include,节假日,chinese,python,weekends,datetime,获取,year,holidays
来源: https://www.cnblogs.com/rongge95500/p/15163800.html