How can I get hours from a Python datetime?

后端 未结 2 1102
鱼传尺愫
鱼传尺愫 2021-01-01 10:34

I have a Python datetime, d, and I want to get the number of hours since midnight as a floating point number. The best I\'ve come up with is:

h = ((((d.hour         


        
2条回答
  •  一生所求
    2021-01-01 10:56

    h = (d - d.replace(hour=0,minute=0,second=0)).seconds / 3600.
    

    ... has less division and/or multiplication

提交回复
热议问题