+ 1

How to do time substraction without using datetime

2nd Dec 2016, 10:59 AM
Tolga
Tolga - avatar
3 Respostas
+ 3
you can do it with simple math. timeList1 = input('first time: ').split(':') timeList2 = input('second time: ').split(':') time1, time2 = 0, 0 for x in range(3): time1 += int(timeList1[2-x]) * 60**x time2 += int(timeList2[2-x]) * 60**x timeDelta = time2 - time1 #this will be difference in seconds. #you can use it as is, or convert to h:m:s format timeDeltaList = ['','',''] for x in range(3): timeDeltaList[2-x] = str((timeDelta // 60**x) % 60) print(':'.join(timeDeltaList))
2nd Dec 2016, 2:00 PM
Demeth
Demeth - avatar
0
plz specify what you need to do
2nd Dec 2016, 11:58 AM
Demeth
Demeth - avatar
0
i want to substract two time inputs which are like 15:20;30-14:30:45 (hour:minute:second)but without importing datetime
2nd Dec 2016, 12:08 PM
Tolga
Tolga - avatar