Moment.js Convert Local time to UTC time does work

后端 未结 7 1900
伪装坚强ぢ
伪装坚强ぢ 2021-01-01 18:23

I would like to use Moment.js to convert a local time to UTC equivalent. I believe that I have the correct method in place, but it does not alter the time.

I\'m in S

7条回答
  •  旧时难觅i
    2021-01-01 19:05

    The question is old, but I also faced it. It may be useful to someone:

    Using the method of utcOffset() to calculate the UTC time:

    selectedDate = (moment(selectedDate).add(-(moment().utcOffset()), 'm'));
    

    And explicitly specify UTC:

    selectedDate = moment.parseZone(selectedDate).utc().format();
    

提交回复
热议问题