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))