If you have a valid date string, you can use the Date.parse()
method to convert it to milliseconds.
Date.parse()
returns the number of milliseconds between the date and January 1, 1970:
Example
let msec = Date.parse("March 21, 2012");
document.getElementById("demo").innerHTML = msec;
document.getElementById("demo").innerHTML = msec;
You can then use the number of milliseconds to convert it to a date object:
Example
let msec = Date.parse("March 21, 2012");
const d = new Date(msec);
document.getElementById("demo").innerHTML = d;
const d = new Date(msec);
document.getElementById("demo").innerHTML = d;
Practice Excercise Practice now