Converting a moment to JS Date in ISO format

194 views Asked by At

I have been trying somewhat unsucessfully to convert a date I have in Moment format to a JS Date object that is in the ISO 8601 format. The API library I am using needs the date to be a JS Date object but needs to format to be 8601. When I try this now my moment is the correct time in 24 hour format

Moment {_isAMomentObject: true, _i: '2021-10-07T15:00:00', _f: 'YYYY-MM-DDTHH:mm:ss', _isUTC: true, _pf: {…}, …}
_a: (7) [2021, 9, 7, 15, 0, 0, 0]
_d: Thu Oct 07 2021 11:00:00 GMT-0400 (Eastern Daylight Time) {}
_f: "YYYY-MM-DDTHH:mm:ss"
_i: "2021-10-07T15:00:00"
_isAMomentObject: true
_isUTC: true

but when I convert to a date it tries to fix the timezone so its always off by 4 hours so like momentVar.toDate() =

Thu Oct 07 2021 11:00:00 GMT-0400 (Eastern Daylight Time)

the moment gets set initially through url param:

eventTime=2021-10-07T15:00:00

what is the right get a JS Date object in an ISO 8601 format but not as a string with the .toISOstring() method

0

There are 0 answers