python获取某一年的所有节假日
注:chinese_calander
库需要每年手动更新一次
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
start = datetime.date(year, 1, 1)
end = datetime.date(year, 12, 31)
holidays = chinese_calendar.get_holidays(start, end, include_weekends)
return holidays
本文来自博客园,仅供参考学习,如有不当之处还望不吝赐教,不胜感激!转载请注明原文链接:https://www.cnblogs.com/rong-z/p/15163800.html
作者:cnblogs用户