Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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