Skip to content
Advertisement

convert dateTime format in react js

i have this date :

Mon Aug 23 2021 15:03:00 GMT+0430 (Iran Daylight Time)

how to convert this format:

2021-10-10T00:00:00

Advertisement

Answer

You can do it as follows:

JavaScript

If you don’t prefer the native way of converting it you can use the library Moment.js.

Your code would look as follows:

JavaScript

If you don’t want to keep the hours, minutes and seconds these examples will work.

Native way:

JavaScript

With Moment.js:

JavaScript

Edit

As RobG mentioned in the comments, the toISOString() function will return the UTC time format. So even one more reason to use moment.js!

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement