这个星期几给了一个日期python [英] which day of week given a date python
本文介绍了这个星期几给了一个日期python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想了解以下内容:
给出了一个日期( datetime
对象),一周中的相应日期是什么。
I want to find out the following:
given a date (datetime
object), what is the corresponding day of the week.
例如星期天是第一天,星期一:第二天..等等
For instance Sunday is the first day, Monday: second day.. and so on
然后如果输入是像今天的日期。
输出可能是 6
(自从它的星期五)
And then if the input is something like Today's date.
The output is maybe 6
(since its Friday)
推荐答案
p>使用 weekday()
( docs ):
>>> import datetime
>>> datetime.datetime.today()
datetime.datetime(2012, 3, 23, 23, 24, 55, 173504)
>>> datetime.datetime.today().weekday()
4
从文档中: / p>
From the documentation:
以星号为0,星期日为6的整数返回星期几。
Return the day of the week as an integer, where Monday is 0 and Sunday is 6.
这篇关于这个星期几给了一个日期python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文