如何从Python中的给定日期获取工作日? [英] how to get weekday from a given date in python?
本文介绍了如何从Python中的给定日期获取工作日?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
2001-10-18 我想计算工作日,例如从上述日期算起的星期一,星期二.有可能在python中吗?
2001-10-18 I want to calculate weekday e.g. Monday, Tuesday from the date given above. is it possible in python?
推荐答案
这里是执行此操作的一种方法:
Here is one way to do this:
dt = '2001-10-18'
year, month, day = (int(x) for x in dt.split('-'))
answer = datetime.date(year, month, day).weekday()
这篇关于如何从Python中的给定日期获取工作日?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文