将timedelta转换为浮点数 [英] Convert timedelta to floating-point
本文介绍了将timedelta转换为浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现所有这些都可以使用浮点计算,但结果
仍然是timedelta对象。
time_d = datetime_1 - datetime_2
time_d_float = float(time_d)
不能工作。
解决方案
您可以使用 total_seconds
方法:
time_d_float = time_d.total_seconds()
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 with floating-points, but the result is still a timedelta object.
time_d = datetime_1 - datetime_2
time_d_float = float(time_d)
does not work.
解决方案
You could use the total_seconds
method:
time_d_float = time_d.total_seconds()
这篇关于将timedelta转换为浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文