Sometimes, we want to fix JSON.stringify changes time of date because of UTC with JavaScript.
In this article, we’ll look at how to fix JSON.stringify changes time of date because of UTC with JavaScript.
How to fix JSON.stringify changes time of date because of UTC with JavaScript?
To fix JSON.stringify changes time of date because of UTC with JavaScript, we can use JSON.parse
to convert the date back to its original format.
For instance, we write
let currentDate = new Date();
currentDate = JSON.stringify(currentDate);
currentDate = new Date(JSON.parse(currentDate));
to call create the currentDate
date object.
Then we call JSON.stringify
to convert the currentDate
object into a JSON string.
Then we call JSON.parse
to parse the date string back to its original format.
And then we use the Date
constructor to convert it back to a date object.
Conclusion
To fix JSON.stringify changes time of date because of UTC with JavaScript, we can use JSON.parse
to convert the date back to its original format.