Skip to content

Instantly share code, notes, and snippets.

@desandro
Created September 30, 2010 21:41
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save desandro/605373 to your computer and use it in GitHub Desktop.
Save desandro/605373 to your computer and use it in GitHub Desktop.
// 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;
};
Copy link

ghost commented Oct 16, 2010

@jfsiii: Tell a lie, I found it. Here's my slightly more verbose offering http://jsfiddle.net/codeinfront/9BFFS/ :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment