Skip to content

Instantly share code, notes, and snippets.

@jfsiii
Forked from desandro/getTimeFromMillis.js
Created October 15, 2010 04:39
Show Gist options
  • Save jfsiii/627622 to your computer and use it in GitHub Desktop.
Save jfsiii/627622 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 = ':' + twoDigit( ~~( ( ms / 1000 ) % 60 ) ),
minutes = ~~( ( ms / ( 1000 * 60 ) ) % 60 ),
hours = ~~( ( ms / ( 1000 * 60 * 60 ) ) );
function twoDigit( n ) { return n < 10 ? '0' + n : n; }
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