Home > other >  Help: how to use a python computing two time
Help: how to use a python computing two time

Time:10-08

For example: 1145-0930=0215, 11 hours, 45 on behalf of the minutes, how to do?

CodePudding user response:

 
Def timeDifference (time1, time2) :
Time1hour=int (time1 [: 2])
Time1min=int (time1 [2:])
Time2hour=int (time2 [: 2])
Time2min=int (time2 [2:])

If time1hour - time2hour & lt; 0:
Print (" input is wrong!" )
The else:
If time1hour==time2hour and time1min & lt; Time2min:
Print (" input is wrong!" )
The else:
If time1min & lt; Time2min:
Time1min +=60
Time1hour -=1

Timediff=STR (time1hour time2hour) + STR (time1min - time2min)
If time1hour - time2hour & lt; 10:
If time1min - time2min & lt; 10:
Timediff="0" + STR (time1hour - time2hour) + "0" + STR (
Time1min - time2min)
The else:
Timediff="0" + STR (time1hour - time2hour) + STR (
Time1min - time2min)
The else:
If time1min - time2min & lt; 10:
Timediff=STR (time1hour time2hour) + "0" + STR (
Time1min - time2min)


Print (timediff)
TimeDifference (" 1145 ", "0900")

CodePudding user response:

Well, thank you very much for the answer, there is a problem, I according to your source input, why would an error

CodePudding user response:

To import into a library, written in front of the
import datetime

CodePudding user response:

refer to the 4th floor vulgar mood response:
to import into a library, written in front,
Import a datetime
thank you, [2:] [: 2] is variable, on behalf of 11 and 45?
  • Related