发布时间:2020-09-07 09:37:20编辑:admin阅读(4611)
最近在做数据分析,需要判断一个日期是否为工作日,节假日。
找到一个现成的插件,蛮好用的。
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("是休息日")执行输出:是休息日
本文参考链接:
https://blog.csdn.net/zhou_438/article/details/101300337
上一篇: Python如何根据日期判断周几
51257
50695
41293
38114
32574
29478
28340
23200
23167
21496
1570°
2287°
1897°
1837°
2149°
1880°
2569°
4308°
4158°
2963°