What method in date-fns that equivalent to moment().toISOString()

Viewed 1875

My old code use momentjs, something like this :

moment(createdAt, 'YYYY-MM-DD HH:mm:ss').toISOString()

What is the equivalent method on date-fns that will reproduce same result ?

2 Answers

Try this,

new Date(createAt).toISOString()

date-fns has a function: formatISO() So, if you want to stay with date-fns you can write:

formatISO(new Date())
Related