Categories
JavaScript Answers

How to change ISO date string to Date object with JavaScript?

Spread the love

To change ISO date string to Date object with JavaScript, we use moment.js.

For instance, we write

const d = moment("2022-11-03T19:38:34.203Z", "YYYY-MM-DD HH:mm").toDate();

to call moment with the ISO date string and the date format to parse the date into a moment object that has the date in UTC.

Then we call toDate to convert it to a JavaScript date object.

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 *