how to use the parseiso function from the date-fns library in typescript

To use the parseISO() function from the date-fns library in TypeScript, you'll first need to install the date-fns library and its type definitions:

npm install date-fns
npm install @types/date-fns --save-dev
60 chars
3 lines

Next, you can import the parseISO() function from the date-fns library and use it like this:

index.ts
import { parseISO } from 'date-fns';

const isoDateString = '2020-10-01T07:30:00.000Z';
const date = parseISO(isoDateString);
console.log(date); // Output: Thu Oct 01 2020 10:30:00 GMT+0300 (Eastern European Summer Time)
221 chars
6 lines

In the code above, we import the parseISO() function from the date-fns library and use it to parse an ISO date string 2020-10-01T07:30:00.000Z. The function returns a JavaScript Date object that we store in the date variable.

Finally, we log the date object to the console, which outputs the date in the local timezone.

gistlibby LogSnag