+ 1
How to do time substraction without using datetime
3 odpowiedzi
+ 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))
0
plz specify what you need to do
0
i want to substract two time inputs which are like 15:20;30-14:30:45 (hour:minute:second)but without importing datetime