Convert timedelta to floating-point

后端 未结 5 2102
攒了一身酷
攒了一身酷 2020-12-13 08:17

I got a timedelta object from the subtraction of two datetimes. I need this value as floating point for further calculations. All that I\'ve found enables the calculation wi

5条回答
  •  一向
    一向 (楼主)
    2020-12-13 09:20

    In Python 3.2 or higher, you can divide two timedeltas to give a float. This is useful if you need the value to be in units other than seconds.

    time_d_min = time_d / datetime.timedelta(minutes=1)
    time_d_ms  = time_d / datetime.timedelta(milliseconds=1)
    

提交回复
热议问题