Last active
February 14, 2021 14:43
-
-
Save flleeppyy/a8e4329825c1f66f18dfb3c8f02ec8ac to your computer and use it in GitHub Desktop.
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
// Input a number and it will format like so, trimming where neccesary | |
// HH:MM:SS | |
// 1:12 | |
// 12:42 | |
// 1:34:15 | |
// 10:00:01 | |
// etc | |
function convertHMS(time) { | |
let hours = Math.floor(time / 3600); | |
time %= 3600; | |
let minutes = Math.floor(time / 60); | |
let seconds = Math.floor(time % 60); | |
let final = hours.toString().padStart(2, '0') + ':' + | |
minutes.toString().padStart(2, '0') + ':' + | |
seconds.toString().padStart(2, '0'); | |
(final.startsWith('00:0')) ? final = final.slice(4) : | |
(final.startsWith('00:')) ? final = final.slice(3) : | |
(final.startsWith('0')) ? final = final.slice(1) : null; | |
return final | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment