简体   繁体   English

moment.js - 从非 UTC 的任何本地日期获取日期

[英]moment.js - Get day from any local date not in UTC

I want to get a date independent of timezone offset我想获得一个独立于时区偏移的日期

const dateOne = moment('Thu Oct 20 2019 12:00:00 GMT-1200').format('YYYY/MM/DD'); // 2019/10/21
const dateTwo = moment('Thu Oct 20 2019 12:00:00 GMT+2300').format('YYYY/MM/DD'); // 2019/10/19

But I need to get 2019/10/20 for both cases.但是对于这两种情况,我都需要得到 2019/10/20。 JS Date and moment as well are formatting a date with influence of GMT offset. JS 日期和时刻也在格式化受 GMT 偏移影响的日期。 How to avoid it?如何避免?

moment.parseZone method worked for me moment.parseZone方法对我有用

const date1 = moment.parseZone('Thu Oct 20 2019 12:00:00 GMT-1200').format('YYYY-MM-DD');
const date2 = moment.parseZone('Thu Oct 20 2019 12:00:00 GMT+2300').format('YYYY-MM-DD');
console.log(date1 === date2); // true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM