How to create JavaScript Date object from date string?

JavascriptWeb DevelopmentFront End Technology

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)
raja
Published on 14-Feb-2018 11:43:42
Advertisements