-
-
Save oldmate45/93686d6c14f9ebd83cc24777474be47a to your computer and use it in GitHub Desktop.
Python: Convert timedelta to HHMMSS string
This file contains hidden or 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 format_timedelta_to_HHMMSS(td): | |
| td_in_seconds = td.total_seconds() | |
| hours, remainder = divmod(td_in_seconds, 3600) | |
| minutes, seconds = divmod(remainder, 60) | |
| hours = int(hours) | |
| minutes = int(minutes) | |
| seconds = int(seconds) | |
| if minutes < 10: | |
| minutes = "0{}".format(minutes) | |
| if seconds < 10: | |
| seconds = "0{}".format(seconds) | |
| return "{}:{}:{}".format(hours, minutes,seconds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment