Created
September 5, 2021 16:24
-
-
Save diegolamonica/75b99e4e01e29106c0b22d27c50169d0 to your computer and use it in GitHub Desktop.
Convert seconds to 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
function timing(duration) { | |
const slots = [] | |
duration = Math.ceil(duration) | |
while (duration > 59 && slots.length < 2) { | |
slots.push( (duration % 60).toString().padStart(2, '0')) | |
duration = Math.floor(duration / 60) | |
} | |
if( duration > 0 ) slots.push(duration); | |
return slots.reverse().join(':') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment