Moment.js isSame无法正常工作

时间:2019-10-31 10:46:52

标签: momentjs

我正在尝试比较以下瞬间对象。它们不应为true,但始终返回true。我不确定哪里错了。

时刻对象1:

{
  _a: (7) [2019, 10, 1, 3, 0, 0, 0]
  _d: Fri Nov 01 2019 03:00:00 GMT+0800 (Singapore Standard Time) {}
  _f: "YYYY-MM-DDTHH:mm:ssZ"
  _i: "2019-11-01T03:00:00+08:00"
  _isAMomentObject: true
  _isUTC: true
  _isValid: true
  _locale: A {_ordinalParse: /\d{1,2}(th|st|nd|rd)/, _abbr: "en", _config: {…}, 
  _ordinalParseLenient: /\d{1,2}(th|st|nd|rd)|\d{1,2}/, ordinal: ƒ}
  _offset: 0
  _pf: {empty: false, unusedTokens: Array(0), unusedInput: Array(0), overflow: 
  -1, charsLeftOver: 0, …}
  _tzm: 480
  _z: null
  __proto__: Object
}

时刻对象2:

{
  _a: (7) [2019, 9, 31, 19, 5, 46, 0]
  _d: Thu Oct 31 2019 18:39:05 GMT+0800 (Singapore Standard Time) {}
  _f: "YYYY-MM-DDTHH:mm:ssZ"
  _i: "2019-10-31T19:05:46+08:00"
  _isAMomentObject: true
  _isUTC: true
  _isValid: true
  _locale: A {_ordinalParse: /\d{1,2}(th|st|nd|rd)/, _abbr: "en", _config: {…}, 
  _ordinalParseLenient: /\d{1,2}(th|st|nd|rd)|\d{1,2}/, ordinal: ƒ}
  _offset: 0
  _pf: {empty: false, unusedTokens: Array(0), unusedInput: Array(0), overflow: 
  -1, charsLeftOver: 0, …}
  _tzm: 480
  _z: null
  __proto__: Object
}

假设Moment对象1是moment1,Moment对象2是moment2,当我执行以下操作时,它始终返回 true

if (moment1.isSame(moment2, 'day')) {
  return true;
} else {
  return false;
}

我正在使用的即时版本为2.12.0,并且我不能随意更改即时版本。

其他信息:我尝试使用以下代码记录一下moment1和moment2:

console.log(JSON.stringify(moment1)) //2019-10-31T19:00:00.000Z <== causing the problem
console.log(JSON.stringify(moment2)) //2019-10-31T11:05:46.000Z

我在这里做什么错了?

0 个答案:

没有答案