Why do Python's datetime.strftime('%w') and datetime.weekday() use different indexes for the days of the week?

前端 未结 3 2091
梦毁少年i
梦毁少年i 2021-02-02 12:47

In Python, showing the day of the week as an integer using datetime.strftime() shows a different result than using datetime.weekday().

         


        
3条回答
  •  忘了有多久
    2021-02-02 13:08

    Originally, the ISO 8601 standard used 1 .. 7 to represent Monday through Sunday. For convenience, later on the interpretation 0=Sunday was permitted.

    If you want to use something that is more consistent, try using isoweekday

    The 0=Monday standard is the European convention. I guess that's no surprise :P

提交回复
热议问题