Python"/>
【亲测】Python
进来绝对会让阁下少扑腾一刻钟。哈哈哈哈
试了几个库,还是这个靠谱。拒绝BB,直接上手、操作
pip install chinese_calendar
,记得每年更新一次@_~
from datetime import datetime
from chinese_calendar import is_holiday, get_holiday_detail, is_in_lieu, is_workdaydef holidays_cal(dstr):dt = datetime.strptime(dstr, "%Y-%m-%d")is_holi = is_holiday(dt)print("is_holi :", is_holi ) # 判断当天是否不上班[含调休、放假、周末]# on_holiday, holiday_name = get_holiday_detail(dt)# print(on_holiday, holiday_name )is_wd = is_workday(dt) # 判断是否是工作日,对于某些调休的周末,需要上班的,该值为Trueprint("is_workday:", is_wd)is_lieu = is_in_lieu(dt) # 判断是否为调休日,当日应该上班但放假,利用其它周末的时间,补回该天的班print("is_lieu:", is_lieu)if __name__ == '__main__':dstr = "2023-04-23" # False True False=>非假期,工作日,非调休dstr = "2023-04-29" # True False False=>假期,非工作日,非调休dstr = "2023-04-30" # True False False=>假期,非工作日,非调休dstr = "2023-05-01" # True False False=>假期,非工作日,非调休dstr = "2023-05-02" # True False True=>假期,非工作日,调休日dstr = "2023-05-03" # True False True=>假期,非工作日,调休日dstr = "2023-05-04" # False True False=>非假期,工作日,非调休holidays_cal(dstr)
更多推荐
【亲测】Python
发布评论