添加持续时间时的日期时间格式

时间:2018-05-16 05:15:11

标签: python datetime time

time_1 = datetime.timedelta(hours = hours_1, minutes = minutes_1, seconds = seconds_1)
time_2 = datetime.timedelta(hours = hours_2, minutes = minutes_2, seconds = seconds_2)

添加时会在dayshours中给出答案,但我真的只想要总小时数。

1 个答案:

答案 0 :(得分:0)

这应该有所帮助。

import datetime

time_1 = datetime.timedelta(hours = 10, minutes = 2, seconds = 5)
time_2 = datetime.timedelta(hours = 30, minutes = 5, seconds = 7)

print(time_1 + time_2)
print(((time_1 + time_2).total_seconds()/60)/60)

<强>输出:

1 day, 16:07:12
40.12