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);


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

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


Current Date: Mon Jan 01 2018 00:00:00 GMT+0530 (India Standard Time)
Published on 14-Feb-2018 11:43:42