- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert a string in to date object in JavaScript?
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.
Example
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.
<html> <body> <script> var str = '{"name":"Ram", "DOB":"1980-11-1", "country":"India"}'; var dateObj = JSON.parse(str); dateObj.DOB = new Date(dateObj.DOB); document.write(dateObj.DOB); </script> </body> </html>
Output
Thu Nov 01 0198 00:00:00 GMT+0553 (India Standard Time)
Advertisements