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

前端 未结 26 1470
迷失自我
迷失自我 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:26

    Assuming you are given the day, month, and year, you could do:

    import datetime
    DayL = ['Mon','Tues','Wednes','Thurs','Fri','Satur','Sun']
    date = DayL[datetime.date(year,month,day).weekday()] + 'day'
    #Set day, month, year to your value
    #Now, date is set as an actual day, not a number from 0 to 6.
    
    print(date)
    

提交回复
热议问题