How to convert a string in to date object in JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

To convert a string in to date object Date() method should be used. This method creates a date instance that represents a single moment in time in a platform-independent format.


In the following example a string named "str" is initially parsed using JSON.parse() method and then converted in to date object using Date() method.

Live Demo 

   var str = '{"name":"Ram", "DOB":"1980-11-1", "country":"India"}';
   var dateObj = JSON.parse(str);
   dateObj.DOB = new Date(dateObj.DOB);


Thu Nov 01 0198 00:00:00 GMT+0553 (India Standard Time)
Updated on 29-Jun-2020 11:48:18