Parse a JSON Date in JavaScript
To parse a JSON date:
Use the
toJSON()
method to get a string representation of theDate
object.Pass the JSON string to the
Date()
constructor.The
Date()
constructor will parse the ISO string and create aDate
objec
const json = new Date().toJSON();
console.log(json); // 👉️ "2022-01-23T09:04:45.904Z"
const date = new Date(json);
console.log(date); // 👉️ Sun Jan 23 2022 11:04:45
Last updated
Was this helpful?