If the seconds is less than an hour then the format returned will be MM:SS
Last active
December 14, 2017 07:43
-
-
Save ariona/bc10197b10954753cc5703608a7e3b32 to your computer and use it in GitHub Desktop.
Formatting seconds times to HH:MM:SS
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
formatTime(seconds) { | |
return seconds > 3600 | |
? | |
[ | |
parseInt(seconds / 60 / 60), | |
parseInt(seconds / 60 % 60), | |
parseInt(seconds % 60) | |
].join(":").replace(/\b(\d)\b/g, "0$1") | |
: | |
[ | |
parseInt(seconds / 60 % 60), | |
parseInt(seconds % 60) | |
].join(":").replace(/\b(\d)\b/g, "0$1") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment