Converting a string to a date in JavaScript
I have a valid date string, how I can convert it to a date in JavaScript
1 Answer
Converting a string to a date in JavaScript by following these steps:
- You need to have a valid date string
- Use the
Date.parse()
method to convert it to milliseconds. - You can then use the number of milliseconds to convert it to a date object:
example
var tex= Date.parse("Feb 5, 2020");
console.log(new Date(tex)); // Wed Feb 05 2020 00:00:00 GMT+0200 (Eastern European Standard Time)
answer Link