Created
October 27, 2016 12:20
-
-
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)
This file contains hidden or 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
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