- PyCharm找到
Preferences --> Project --> Project Interpreter
,如图点击加号,搜索安装chinesecalendar
包
image.png
- 执行如下代码,可判断指定日期第二天是否为节假日或工作日
from chinese_calendar import is_workday, is_holiday
import datetime
import time
detester = '20200430'
date = time.strptime(detester, '%Y%m%d') # <class 'time.struct_time'>
year, month, day = date[:3]
target_date = datetime.date(year, month, day)
target_tomorrow = target_date + datetime.timedelta(days=1) # 第二天
print(is_holiday(target_tomorrow)) # True
print(is_workday(target_tomorrow)) # False
网友评论