1function millisToMinutesAndSeconds(millis) {
2 var minutes = Math.floor(millis / 60000);
3 var seconds = ((millis % 60000) / 1000).toFixed(0);
4 return minutes + ":" + (seconds < 10 ? '0' : '') + seconds;
5}
6
7millisToMinutesAndSeconds(298999); // "4:59"
8millisToMinutesAndSeconds(60999); // "1:01"
9
1const millisToMinutesAndSeconds = (millis) => {
2 var minutes = Math.floor(millis / 60000);
3 var seconds = ((millis % 60000) / 1000).toFixed(0);
4 //ES6 interpolated literals/template literals
5 //If seconds is less than 10 put a zero in front.
6 return `${minutes}:${(seconds < 10 ? "0" : "")}${seconds}`;
7}
8
1function msToTime(s) {
2
3 // Pad to 2 or 3 digits, default is 2
4 function pad(n, z) {
5 z = z || 2;
6 return ('00' + n).slice(-z);
7 }
8
9 var ms = s % 1000;
10 s = (s - ms) / 1000;
11 var secs = s % 60;
12 s = (s - secs) / 60;
13 var mins = s % 60;
14 var hrs = (s - mins) / 60;
15
16 return pad(hrs) + ':' + pad(mins) + ':' + pad(secs) + '.' + pad(ms, 3);
17}
18
19console.log(msToTime(55018))