Reputation: 53
Need some help on this. Not sure how to start.
I have list of starting time which looks like
How can I get the Clean_Start_Time in Python from Start_Time (string)? 25h is supposed to be 0100 and 24h is 0000.
Upvotes: 0
Views: 38
Reputation: 2279
This should work. It splits the string on :
, gets the remainder of the hour divided by twenty four then joins the string back together and returns it.
def modulo24(start_time):
hour, minute, second = start_time.split(':')
hour = str(int(hour) % 24)
clean_start_time = ":".join([hour, minute, second])
return clean_start_time
Upvotes: 1