Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 617
Jim Johnson Avatar asked Aug 27 '18 06:08

Jim Johnson


People also ask

How do you convert moments to dates?

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.

Is moment or date-fns better?

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.

How do you get moments from the day?

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.


1 Answers

Try this,

new Date(createAt).toISOString()
like image 99
Janith Avatar answered Sep 29 '22 06:09

Janith