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 ?
Date Formatting Date format conversion with Moment is simple, as shown in the following example. moment(). format('YYYY-MM-DD'); Calling moment() gives us the current date and time, while format() converts it to the specified format.
Date-fns simplifies the JavaScript data manipulations by providing a variety of functions. It provides more than 200 different time-related functions, and unlike MomentJS, it allows you to import a selected set of functions as needed.
The moment(). day() method is used to get or set the day of week of the Moment object. The day of the week can have a value between 0 and 6, where 0 denotes Sunday and 6 denotes Saturday. A value outside this range will make it go to the previous or upcoming weeks.
Try this,
new Date(createAt).toISOString()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With