The parseISO
function from date-fns
allows us to parse a date string in ISO format (e.g. "2022-02-14T11:20:45.123Z") and return a Date object in JavaScript.
Here's an example usage:
index.tsx200 chars7 lines
In the code above, we first import the parseISO
function from the date-fns
library. We then create an ISO-formatted date string and pass it to the parseISO
function. The function returns a Date object which we store in the dateObject
variable. Finally, we log the value of dateObject
to the console.
Note that parseISO
is only for parsing ISO-formatted date strings. If you need to parse date strings in other formats, you can use the parse
function from date-fns
instead.
gistlibby LogSnag