get milliseconds in javascript code example

Example 1: what 1hr in milliseconds in javascript

/*
** Time in milliseconds

1 second = 1000 milliseconds
15 minutes = 900000 milliseconds
30 seconds = 30000 milliseconds	
1 minute = 60000 milliseconds
5 minutes = 300000 milliseconds
30 minutes = 1800000 milliseconds
45 minutes = 2700000 milliseconds
1 hour = 3600000 milliseconds

*/

Example 2: convert milliseconds to time javascript

function msToTime(s) {

  // Pad to 2 or 3 digits, default is 2
  function pad(n, z) {
    z = z || 2;
    return ('00' + n).slice(-z);
  }

  var ms = s % 1000;
  s = (s - ms) / 1000;
  var secs = s % 60;
  s = (s - secs) / 60;
  var mins = s % 60;
  var hrs = (s - mins) / 60;

  return pad(hrs) + ':' + pad(mins) + ':' + pad(secs) + '.' + pad(ms, 3);
}

console.log(msToTime(55018))