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

前端 未结 3 2063
梦毁少年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 12:53

    Maybe weekday is based on locale while strftime is not? Because I have different output:

    In [14]: d.strftime("%A")
    Out[14]: 'Sunday'
    
    In [15]: d.strftime("%w")
    Out[15]: '0'
    
    In [16]: now.weekday()
    Out[16]: 0
    

提交回复
热议问题