Parse a JSON Date in JavaScript
To parse a JSON date:
Use the
toJSON()method to get a string representation of theDateobject.Pass the JSON string to the
Date()constructor.The
Date()constructor will parse the ISO string and create aDateobjec
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?