Changing the Utc Date to Local Date using moment.js

后端 未结 4 1955
忘掉有多难
忘掉有多难 2020-12-17 02:01

i\'m using moment.js with timezones for date manipulation in a webapp. i\'m storing all the dates in UTC and return them to UI as UTC. I\'m having the timezone of the user.

4条回答
  •  没有蜡笔的小新
    2020-12-17 02:41

    You can try:

    moment.utc(utcDate).tz(timezone).format()
    

    But it shouldn't matter. They should both produce: "2013-10-16T06:31:59-04:00".

    It works for me, running on Chrome 30, so it's probably browser related.

    If you're running Moment.js 2.3.1 or earlier on IE8, then it's a side effect of issue #1175, which was fixed in 2.4.0. Updating to the latest version should solve the problem.

提交回复
热议问题