Created
October 24, 2020 10:22
-
-
Save vkbo/a61a2c2f22b65ec209b9b1025667faa8 to your computer and use it in GitHub Desktop.
A simple and fast Python 3.6+ function for formatting an integer representing time in seconds to HH:MM:SS or d-HH:MM:SS format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def formatTime(tS): | |
"""Format a time in seconds in HH:MM:SS format or d-HH:MM:SS format | |
if a full day or longer. | |
""" | |
if isinstance(tS, int): | |
if tS >= 86400: | |
return f"{tS//86400:d}-{tS%86400//3600:02d}:{tS%3600//60:02d}:{tS%60:02d}" | |
else: | |
return f"{tS//3600:02d}:{tS%3600//60:02d}:{tS%60:02d}" | |
return "ERROR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment