Created
September 30, 2010 21:41
-
-
Save desandro/605373 to your computer and use it in GitHub Desktop.
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
// converts milliseconds to '3:45' or if hours > 0, '2:01:23' | |
var getTimeFromMillis = function( ms ) { | |
var seconds = ~~( ( ms / 1000 ) % 60 ), | |
minutes = ~~( ( ms / ( 1000 * 60 ) ) % 60 ), | |
hours = ~~( ( ms / ( 1000 * 60 * 60 ) ) ), | |
twoDigit = function ( n ) { | |
return n < 10 ? '0' + n : n; | |
}, | |
seconds = ':' + twoDigit( seconds ); | |
return hours > 0 ? hours + ':' + twoDigit( minutes ) + seconds : minutes + seconds; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jfsiii: Tell a lie, I found it. Here's my slightly more verbose offering http://jsfiddle.net/codeinfront/9BFFS/ :)