首页 > 解决方案 > Moment.js 格式不正确

问题描述

我正在使用moment.js我的 react-native 项目日期时间格式化程序。我想从 UTC 日期中删除时区。因为我的时区是 GMT+8000,所以对于 UTC 偏移量是正确的,当我添加时format('YYYY/MM/DD 00:00'),结果减去一天。

console.log(moment.utc());
-> Moment {_isAMomentObject: true, _isUTC: true, _pf: {…}, _locale: Locale, _d: Wed Jul 11 2018 11:08:57 GMT+0800 (Malaysia Time), …}

console.log(moment.utc().utcOffset(new Date().getTimezoneOffset()));
->Moment {_isAMomentObject: true, _isUTC: true, _pf: {…}, _locale: Locale, _d: Wed Jul 11 2018 03:08:57 GMT+0800 (Malaysia Time), …}

console.log(moment.utc().utcOffset(new Date().getTimezoneOffset()).format('YYYY/MM/DD 00:00'));
->"2018/07/10 00:00"

知道怎么做吗?或者也许我做错了?

标签: javascriptdatedatetimemomentjs

解决方案


推荐阅读