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
1var date = new Date("11/21/1987 16:00:00"); // some mock date
2var milliseconds = date.getTime();
3// This will return you the number of milliseconds
4// elapsed from January 1, 1970
5// if your date is less than that date, the value will be negative
6
7console.log(milliseconds);
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))