Reputation: 61
when i used the following code. I do understand that i am adding 12 to the time given and it returns 24:00:00 but i am not able to understand how to get 00:00:00.
My timestamp has list of time values.
r = timestamp[:-2] if timestamp[-2:] == "AM" else str(int(timestamp[:2]) + 12) + timestamp[2:8]
Upvotes: 0
Views: 166
Reputation: 49318
Use modulo arithmetic to divide by 24 and get the remainder. Change this:
int(timestamp[:2]) + 12
to this:
(int(timestamp[:2]) + 12) % 24
Demonstration:
>>> 12 + 12
24
>>> (12 + 12) % 24
0
Upvotes: 2