Created
March 13, 2013 11:21
-
-
Save edwinwebb/5151220 to your computer and use it in GitHub Desktop.
Format MS to Time Stamp "MM:SS:XX" in Javascript
This file contains hidden or 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 formatSeconds(seconds, format) { | |
| var ms = Math.floor((seconds*1000) % 1000); | |
| var s = Math.floor(seconds%60); | |
| var m = Math.floor((seconds*1000/(1000*60))%60); | |
| var strFormat = format || "MM:SS:XX"; | |
| if(s < 10) s = "0" + s; | |
| if(m < 10) m = "0" + m; | |
| if(ms < 10) ms = "0" + ms; | |
| strFormat = strFormat.replace(/MM/, m); | |
| strFormat = strFormat.replace(/SS/, s); | |
| strFormat = strFormat.replace(/XX/, ms.toString().slice(0,2)); | |
| return strFormat; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment