I created a function that detects and converts milliseconds to minutes and seconds. What I'd like to do is prepend a zero on either (or both) the minute and second variables if the number comes out to be less than ten. So for instance if I had an integer 184213
which evaluates to 3:4
I'd like it to be 03:04
. Is there a short and concise way to do this without having to write out a long conditional or ternary?
msToTime(184213);
function msToTime(milliseconds) {
var minutes = parseInt(milliseconds/(1000*60)%60),
seconds = parseInt((milliseconds/1000)%60);
return minutes + ':' + seconds;
}