Created
October 2, 2022 23:30
-
-
Save fauxneticien/5b0067a7c2540055ce49c5be25e8f75a to your computer and use it in GitHub Desktop.
Convert milliseconds to hours-minutes-seconds string format to use within identifiers
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 ms_to_hms(start_ms: int) -> str: | |
import math | |
""" | |
Convert milliseconds to hours-minutes-seconds string format to use within identifiers | |
e.g. 3990060 ms -> '01h06m30.060' | |
""" | |
s, ms = divmod(start_ms, 1000) | |
m, s = divmod(s, 60) | |
h, m = divmod(m, 60) | |
ms = str(round(ms)).zfill(3) | |
s = str(math.floor(s)).zfill(2) | |
m = str(math.floor(m)).zfill(2) | |
h = str(math.floor(h)).zfill(2) | |
return f"{h}h{m}m{s}.{ms}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment