Skip to content

Instantly share code, notes, and snippets.

@cleishm
Created March 19, 2012 18:44
Show Gist options
  • Save cleishm/2123604 to your computer and use it in GitHub Desktop.
Save cleishm/2123604 to your computer and use it in GitHub Desktop.
Format a time to H:MM:SS.mmm
function formatTime(time) {
var hours = Math.floor(time / 3600000);
var min = Math.floor(((time % 3600000) / 60000));
var sec = Math.floor(((time % 60000) / 1000));
var msec = time % 1000;
if (hours < 10)
hours = '0' + hours;
if (min < 10)
min = '0' + min;
if (sec < 10)
sec = '0' + sec;
if (msec < 10)
msec = '00' + msec;
else if (msec < 100)
msec = '0' + msec;
return hours + ':' + min + ':' + sec + '.' + msec;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment