how to add two different times in python

Solutions on MaxInterview for how to add two different times in python by the best coders in the world

showing results for - "how to add two different times in python"
Cletus
10 Jan 2021
1import datetime as dt
2t1 = dt.datetime.strptime('12:00:00', '%H:%M:%S')
3t2 = dt.datetime.strptime('02:00:00', '%H:%M:%S')
4time_zero = dt.datetime.strptime('00:00:00', '%H:%M:%S')
5print((t1 - time_zero + t2).time())