Python识别中国工作日,节假日,调休日。

您所在的位置:网站首页 工作日节假日日历怎么写 Python识别中国工作日,节假日,调休日。

Python识别中国工作日,节假日,调休日。

2023-09-07 12:33| 来源: 网络整理| 查看: 265

Python识别中国工作日,节假日,调休日 简单修改,支持2022年至2004年之间所有工作日,节假日,调休工作日

工作需要使用Python识别工作日功能,在Python第三库,使用 pip install chinese_calendar,安装正常使用。随着时间推移,发现不支持2020年。

一、gitee下载库

在这里插入图片描述下载完成后,修改名称为chinese_calendar,并解压到Python安装路径的Lib文件夹下 D:\Program Files\python368\Lib 在这里插入图片描述

二、代码使用

代码如下(示例):

import datetime from chinese_calendar import is_workday from chinese_calendar import is_holiday from chinese_calendar import is_in_lieu #获取现在的时间 date0 = datetime.datetime.now().date() #自定义时间 date2 = '2022-02-04' date3 = datetime.date(*map(int,date2.split('-'))) #验证自定义时间格式 print(date3) print(type(date3)) #验证是否是工作日 if is_workday(date3): print("是工作日0") else: print("是休息日0") #结果:是休息日0,判断为True if is_workday(date3) is True: print('工作日判断为真') else: print("工作日判断为假") #结果:是休息日0。输输出结果为”工作日判断为假“ #验证是否是休息日 if is_holiday(date3): print("是休息日1") else: print('是工作日1') #结果:是休息日1。判断结果为Trus。 #验证是否为调休日期 if is_in_lieu(date3): print('是节假调休日') else: print('不是节假调休日') #结果是:节假日调休日,判断结果为True。 总结

从最一开始的PIP下载引用的。网址https://pypi.org/project/chinesecalendar/



【本文地址】


今日新闻


推荐新闻


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