Create a local date from a UTC date string in Moment.js

前端 未结 2 2026
野性不改
野性不改 2021-01-26 18:23

Given a UTC date string (formatted: YYYYMMDDHHmmss) I\'d like to create a date with the local timezone using Moment.js. I have tried the following:

var utcDateSt         


        
2条回答
  •  野性不改
    2021-01-26 18:55

    Just use the .local() function, added in version 1.5.0.

    var localDate = moment.utc(utcDateStr, 'YYYYMMDDHHmmss').local();
    

提交回复
热议问题