var date = new Date("11/21/1987 16:00:00"); // some mock date
var milliseconds = date.getTime();
// This will return you the number of milliseconds
// elapsed from January 1, 1970
// if your date is less than that date, the value will be negative
console.log(milliseconds);
//Date.now() gives us the current time in milliseconds counted from 1970-01-01
const todaysDate = Date.now();
//Let's add 1 year of milliseconds.
// We know that there is 1000 milliseconds in 1 second.
// 60 seconds in 1 minute,
// 60 minutes in 1 hour,
// 24 hours in 1 day
// and 365 days in one year (leap year not included)
const dateInOneYear = new Date(todaysDate+(1000*60*60*24*365));
//To print them out in a readable way
console.log(new Date(todaysDate).toLocaleDateString())
console.log(new Date(dateInOneYear).toLocaleDateString())
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))
const time1 = new Date(0);
// epoch time
console.log(time1); // Thu Jan 01 1970 05:30:00
// 100000000000 milliseconds after the epoch time
const time2 = new Date(100000000000)
console.log(time2); // Sat Mar 03 1973 15:16:40