【亲测】Python

编程入门 行业动态 更新时间:2024-10-24 22:21:05

【亲测】<a href=https://www.elefans.com/category/jswz/34/1770869.html style=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

本文发布于:2024-03-13 19:40:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1734674.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!