How to convert Moment.js date to users local timezone?

后端 未结 4 1307
故里飘歌
故里飘歌 2020-12-01 02:17

I use the Moment.js and Moment-Timezone frameworks, and have a Moment.js date object which is explicitly in UTC timezone. How can I convert that to the current timezone of t

4条回答
  •  日久生厌
    2020-12-01 03:01

    Use utcOffset function.

    var testDateUtc = moment.utc("2015-01-30 10:00:00");
    var localDate = moment(testDateUtc).utcOffset(10 * 60); //set timezone offset in minutes
    console.log(localDate.format()); //2015-01-30T20:00:00+10:00
    

提交回复
热议问题