Reputation: 1
This is what I have so far
H1 = input("insert hour 0-23 :")
M1 = input("insert minute 1-60 :")
S1 = input("insert second :")
print H1,":",M1,":",S1
H2 = input("insert hour 0-23 :")
M2 = input("insert minute 1-60 :")
S2 = input("insert second 1-60 :")
print H2,":",M2,",",S2
where I am stuck is getting the difference between the two times and also converting the difference into seconds.
Which I think after I've properly got the difference would not be to hard when I've tried things like (H3 = H2 - H1 or H3 = H1 - H2) if the first number is lower than the second I obviously get a negative number which I do not want
I want the numbers to go along with a 24 hour clock
Upvotes: 0
Views: 428
Reputation: 3892
One way would be to use modulo subtraction (Modular Arithmetics).
Just perform something like that:
mRemainder, hRemainder = 0;
S = (S1 - S2) mod 60;
if (S1 < S2) mRemainder = 1;
M = (M1 - M2 - mRemainder) mod 60;
if (M1 < M2 + mRemainder) hRemainder = 1;
H = (H1 - H2 - hRemainder) mod 24;
Upvotes: 1