最近在做数据分析,需要判断一个日期是否为工作日,节假日。
找到一个现成的插件,蛮好用的。
https://pypi.org/project/chinesecalendar/
判断某年某月某一天是不是工作日/节假日。 支持 2004年 至 2020年,包括 2020年 的春节延长。 兼容 Python2 与 Python3.
pip install chinesecalendar
import datetime
from chinese_calendar import is_workday
date = datetime.datetime.now().date()
if is_workday(date):
print("是工作日")
else:
print("是休息日")
执行输出:是工作日
import datetime
from chinese_calendar import is_workday
date = datetime.datetime(2020, 8, 9)
if is_workday(date):
print("是工作日")
else:
print("是休息日")
执行输出:是休息日
本文参考链接:
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有