Moment JS - parse UTC and convert to Local and vice versa [duplicate]

  • On Item 1 - Yes, that's one way to do it. However, if the output format is just going to be an ISO8601 UTC timestamp, then you can call toISOString directly on the original moment. Since UTC is implied by the output, it would be redundant to call utc() again.

  • On Item 2 - Just like the utc() function, there's also a local() function. Once you have a moment object, you can use toDate or format or any other of the functions described in the documentation. No, you do not need to create a new moment using the generated date object.

    moment.utc(utcDateTime, utcDateTimeFormat).local().format(specifiedFormat)
    

    Again, there's more than one way to do things here. If the utcDateTime is already in ISO8601 format, and contains either a Z or an offset like -01:00, then that will be taken into account and you can simply do this:

    moment(utcDateTime).format(specifiedFormat)
    
  • On the last item you mentioned about time zones, it's difficult to tell what you are asking. You should elaborate with specific details in a new question.