Skip to content
Advertisement

convert js datetime to moment

I have this format of datetime currently stored in res.data[i].time:

2022-05-18T13:00:00.000Z

what I want to do is convert it to moment format. When i do this:

moment().toDate()

it gives me this:

Tue May 10 2022 13:00:00 GMT-0400 (Eastern Daylight Saving Time)

what I want to need to do is convert 2022-05-18T13:00:00.000Z to moment somehow. I tried:

moment().toDate(res.data[i].time)

but that doesn’t work either. is there a way to do this?

Advertisement

Answer

Just let whatever = moment(res.data[i].time) should instantiate the moment object with the time string provided. You can then do whatever you need from there.

Advertisement