Created
April 16, 2012 03:35
-
-
Save s4y/2396233 to your computer and use it in GitHub Desktop.
JavaScript function for formatting a duration of time
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 formatDuration(duration){ | |
var seconds = Math.abs(Math.ceil(duration / 1000)), | |
h = (seconds - seconds % 3600) / 3600, | |
m = (seconds - seconds % 60) / 60 % 60, | |
s = seconds % 60; | |
return (duration < 0 ? '-' : '') + h + ':' + zeroPad(m.toString(), 2) + ':' + zeroPad(s.toString(), 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment