How do I get the day of week given a date?

前端 未结 26 1459
迷失自我
迷失自我 2020-11-22 04:40

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, Mond

26条回答
  •  醉酒成梦
    2020-11-22 05:05

    Use weekday():

    >>> import datetime
    >>> datetime.datetime.today()
    datetime.datetime(2012, 3, 23, 23, 24, 55, 173504)
    >>> datetime.datetime.today().weekday()
    4
    

    From the documentation:

    Return the day of the week as an integer, where Monday is 0 and Sunday is 6.

提交回复
热议问题