Created
September 19, 2014 20:48
-
-
Save sheodox/4959b372c56745c1f5de to your computer and use it in GitHub Desktop.
Time formatter
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
function formatTime(seconds) { | |
var fTime = []; | |
fTime[0] = Math.floor(seconds / 86400); | |
seconds %= 86400; | |
fTime[1] = Math.floor(seconds / 3600); | |
seconds %= 3600; | |
fTime[2] = Math.floor(seconds / 60); | |
seconds %= 60; | |
fTime[3] = seconds; | |
for (var i = 0; i < 4; i++) { | |
fTime[i] = fTime[i] < 10 ? '0' + fTime[i] : fTime[i]; | |
} | |
return fTime.join(':'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment