Moment.js Convert Local time to UTC time does work

后端 未结 7 1852
伪装坚强ぢ
伪装坚强ぢ 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条回答
  • 2021-01-01 19:15

    After few frustrating hours, I found what was the problem

    Short Answer: To convert time to utc, we need to use format()

    Long Answer: Take the example

    moment.utc(1559586600000).format('LLL')

    .utc sets the isUTC flag to true.

    When logging the date, the d key always shows the time in local timezone. (Which makes us believe its not working properly - as shown in your screenshot)

    But we need to use .format to get the date/time in UTC format.

    The above code returns June 3, 2019 6:30 PM which is the correct UTC time.

    0 讨论(0)
提交回复
热议问题