Created
March 19, 2012 18:44
-
-
Save cleishm/2123604 to your computer and use it in GitHub Desktop.
Format a time to H:MM:SS.mmm
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
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