【问题标题】:how to get weekday from a given date in python?如何从python中的给定日期获取工作日?
【发布时间】:2017-10-19 13:52:48
【问题描述】:

2001-10-18 我想计算工作日,例如从上述日期开始的星期一、星期二。在python中有可能吗?

【问题讨论】:

标签: python datetime


【解决方案1】:

这是一种方法:

dt = '2001-10-18'
year, month, day = (int(x) for x in dt.split('-'))    
answer = datetime.date(year, month, day).weekday()

【讨论】:

  • 你可以使用format来转换ISO日期时间。
【解决方案2】:

日期时间对象有 weekday()isoweekday() 方法。

Python doc

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 2021-02-15
    • 2023-03-26
    • 1970-01-01
    相关资源
    最近更新 更多