Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert a number of seconds as integer to a string of hours, minutes and seconds (HH:MM:SS)
var secondsToTime = function(s) {
var pad = function(v) {
return v < 10 ? '0' + v : v.toString();
}
var result = '';
for (var i = 0; i < 3; i++) {
result = pad(s % 60) + (i ? ':' : '') + result;
s = Math.floor(s / 60);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment