Changing the Utc Date to Local Date using moment.js

后端 未结 4 1950
忘掉有多难
忘掉有多难 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 03:04

    Even if you don't know the timezone, you get the client offset and use like this,

    let utcTime = "2017-02-02 08:00:13.567";
    var offset = moment().utcOffset();
    var localText = moment.utc(utcTime).utcOffset(offset).format("L LT");
    

    Try this JsFiddle

提交回复
热议问题