'How to convert Text 25:40:45 to 1:40:45 (24 hours format) in Python

Need some help on this. Not sure how to start. I have list of starting time which looks like enter image description here

How can I get the Clean_Start_Time in Python from Start_Time (string)? 25h is supposed to be 0100 and 24h is 0000.



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nathan Mills