Last active
January 2, 2016 17:18
-
-
Save kalmanolah/8335443 to your computer and use it in GitHub Desktop.
A little javascript snippet for formatting times in seconds.
This file contains 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(secs, format) { | |
if (!format) { | |
format = '%hh %mm %ss'; | |
} | |
var hours = ("0" + Math.floor(secs / 3600)).slice(-2), | |
minutes = ("0" + Math.floor((secs % 3600) / 60)).slice(-2), | |
seconds = ("0" + (secs % 60)).slice(-2); | |
return format | |
.replace('%h', hours) | |
.replace('%m', minutes) | |
.replace('%s', seconds); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment