簡體   English   中英

moment.js - 從非 UTC 的任何本地日期獲取日期

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

我想獲得一個獨立於時區偏移的日期

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

但是對於這兩種情況,我都需要得到 2019/10/20。 JS 日期和時刻也在格式化受 GMT 偏移影響的日期。 如何避免?

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