Categories
JavaScript Answers

How to convert an ISO date to the date format yyyy-mm-dd with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *