Sometimes, we want to convert a date string to ISO date with JavaScript.
In this article, we’ll look at how to convert a date string to ISO date with JavaScript.
How to convert a date string to ISO date with JavaScript?
To convert a date string to ISO date with JavaScript, we can use the date’s toISOString method.
For instance, we write:
const dateString = '12/01/2022'
const s = new Date(dateString).toISOString()
console.log(s)
to create a Date instance from dateString.
Then we call toISOString to return an ISO 8601 date string.
Therefore, s is "2022-12-01T08:00:00.000Z".
Conclusion
To convert a date string to ISO date with JavaScript, we can use the date’s toISOString method.
