how to add hours in python? in the format below:
hour1= '20:00'
hour2= '25:00'
sum= hour1 + hour2
so the correct print and formatted as I want it would be: result of the sum 45:00:00
how to add hours in python? in the format below:
hour1= '20:00'
hour2= '25:00'
sum= hour1 + hour2
so the correct print and formatted as I want it would be: result of the sum 45:00:00
I just copied and edited this answer:
import datetime
# for show hours use below format
timeList = ['25:00:00', '20:00:00']
mysum = datetime.timedelta()
for i in timeList:
(h, m, s) = i.split(':')
d = datetime.timedelta(hours=int(h), minutes=int(m), seconds=int(s))
mysum += d
print(str(mysum))