Sometimes, we want to convert an ISO date to the date format yyyy-mm-dd with JavaScript.
In this article, we’ll look at how to convert an ISO date to the date format yyyy-mm-dd with JavaScript.
How to convert an ISO date to the date format yyyy-mm-dd with JavaScript?
To convert an ISO date to the date format yyyy-mm-dd with JavaScript, we can call the string substring
method.
For instance, we write
const date = new Date("2022-03-10T02:00:00Z");
const isoDate = date.toISOString().substring(0, 10);
to create a new Date
instance.
Then we call toISOString
to return a string with the ISO date time.
And then we get the date portion of the string with substring
.
Conclusion
To convert an ISO date to the date format yyyy-mm-dd with JavaScript, we can call the string substring
method.