How to create JavaScript Date object from date string?


To create a date object from date string, just add the string like this −

var date = new Date(2018,1,1);

Example

You can try to run the following code to create date object from date string. Here, the month is indexed as 0 for Jan, 1 for Feb, etc in JavaScript −

Live Demo

<html>
   <head>
      <title>JavaScript Dates</title>
   </head>
   <body>
      <script>
         var date;
         date = new Date(2018,0,1);
         document.write("Current Date: "+date);
      </script>
   </body>
</html>

Output

Current Date: Mon Jan 01 2018 00:00:00 GMT+0530 (India Standard Time)

Updated on: 18-Jun-2020

175 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements