Python判断指定日期是不是中国的法定节假日

您所在的位置:网站首页 法定节假日日期 Python判断指定日期是不是中国的法定节假日

Python判断指定日期是不是中国的法定节假日

2023-04-28 14:22| 来源: 网络整理| 查看: 265

中国节假日判断 Python判断某年某月某一天是不是工作日/节假日。

支持 2004年 至 2023年,包括 2020年 的春节延长。

安装 pip install chinesecalendar 升级 pip install -U chinesecalendar

由于次年的节假日安排,取决于国务院发布的日程。 所以本项目一般会在国务院更新以后,发布新的版本。 按照以往的经验,一般是每年的 11月 前后发布新版本。

样例 import datetime # 判断 2018年4月30号 是不是节假日 from chinese_calendar import is_holiday, is_workday april_last = datetime.date(2018, 4, 30) assert is_workday(april_last) is False assert is_holiday(april_last) is True # 或者在判断的同时,获取节日名 import chinese_calendar as calendar # 也可以这样 import on_holiday, holiday_name = calendar.get_holiday_detail(april_last) assert on_holiday is True assert holiday_name == calendar.Holiday.labour_day.value # 还能判断法定节假日是不是调休 import chinese_calendar assert chinese_calendar.is_in_lieu(datetime.date(2006, 2, 1)) is False assert chinese_calendar.is_in_lieu(datetime.date(2006, 2, 2)) is True


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3