| Viewed 44 times

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
Mohammad Qandeel
Answered
15

Converting a string to a date in JavaScript by following these steps:

  1. You need to have a valid date string
  2. Use the Date.parse() method to convert it to milliseconds. 
  3. 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)
 


Related Questions