Skip to content

Instantly share code, notes, and snippets.

@diegolamonica
Created September 5, 2021 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegolamonica/75b99e4e01e29106c0b22d27c50169d0 to your computer and use it in GitHub Desktop.
Save diegolamonica/75b99e4e01e29106c0b22d27c50169d0 to your computer and use it in GitHub Desktop.
Convert seconds to HH:mm:ss format
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