Skip to content

Instantly share code, notes, and snippets.

@perliedman
Created October 27, 2016 12:20
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 perliedman/11a4c2a8395e1abd8653d66dee44d835 to your computer and use it in GitHub Desktop.
Save perliedman/11a4c2a8395e1abd8653d66dee44d835 to your computer and use it in GitHub Desktop.
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