Moment.js 中的弃用警告 - 不是公认的 ISO 格式 - Deprecation warning in Moment.js - Not in a recognized ISO format

10/14 09:19
阅读数 0

问题:

I'm getting a warning that a value provided to moment is not in a recognized ISO format.我收到一条警告,指出提供给 moment 的值不是公认的 ISO 格式。 I changed my variable today with the moment function and still it doesn't work.我今天用 moment 函数更改了我的变量,但它仍然不起作用。

Here's the warning error:这是警告错误:

Deprecation warning: value provided is not in a recognized ISO format.弃用警告:提供的值不是公认的 ISO 格式。 moment construction falls back to js Date(), which is not reliable across all browsers and versions. moment 构造回退到 js Date(),这在所有浏览器和版本中都不可靠。 Non ISO date formats are discouraged and will be removed in an upcoming major release.不鼓励非 ISO 日期格式,并将在即将发布的主要版本中删除。 Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.请参阅http://momentjs.com/guides/#/warnings/js-date/了解更多信息。 Arguments: [0] _isAMomentObject: true, _isUTC: true, _useUTC: true, _l: undefined, _i: 2016-9-26 19:30, _f: undefined, _strict: undefined, _locale: [object Object]参数:[0] _isAMomentObject:真,_isUTC:真,_useUTC:真,_l:未定义,_i:2016-9-26 19:30,_f:未定义,_strict:未定义,_locale:[object Object]

var entryDate = new Date();
var currentDate = entryDate.getDate();

function between(x, min, max) {
  return x.valueOf() >= min.valueOf() && x < max.valueOf();
}

$('#custom1').change(function () {
  if ($('#custom1 :selected').val() == 'AU') {
    var keyword = '';

    var aus1_s = moment.tz('2016-9-26 19:30', 'Australia/Sydney');
    var aus2_s = moment.tz('2016-10-2 19:30', 'Australia/Sydney');
    var aus3_s = moment.tz('2016-10-9 19:30', 'Australia/Sydney');
    var aus4_s = moment.tz('2016-10-16 19:30', 'Australia/Sydney');
    var aus5_s = moment.tz('2016-10-23 19:30', 'Australia/Sydney');
    var aus6_s = moment.tz('2016-10-30 19:30', 'Australia/Sydney');
    var aus6_e = moment.tz('2016-11-5 19:30', 'Australia/Sydney');
  } else if ($('#custom1 :selected').val() == 'NZ') {
    var aus1_s = moment.tz('2016-9-28 20:30', 'Pacific/Auckland');
    var aus2_s = moment.tz('2016-10-4 20:30', 'Pacific/Auckland');
    var aus3_s = moment.tz('2016-10-11 20:30', 'Pacific/Auckland');
    var aus4_s = moment.tz('2016-10-18 20:30', 'Pacific/Auckland');
    var aus5_s = moment.tz('2016-10-25 20:30', 'Pacific/Auckland');
    var aus6_s = moment.tz('2016-11-2 20:30', 'Pacific/Auckland');
    var aus6_e = moment.tz('2016-11-9 20:30', 'Pacific/Auckland');
  } else {
    $('#entryEquals').val('');
    return false;
  }

  var today = moment();

  switch (true) {
    case between(today, aus1_s, aus2_s):
      keyword = 'RElYT04=';
      break;

    case between(today, aus2_s, aus3_s):
      keyword = 'QlJJREU=';
      break;

    case between(today, aus3_s, aus4_s):
      keyword = 'U1lETkVZ';
      break;

    case between(today, aus4_s, aus5_s):
      keyword = 'R1JPT00=';
      break;

    case between(today, aus5_s, aus6_s):
      keyword = 'V0VERElORw==';
      break;

    case between(today, aus6_s, aus6_e):
      keyword = 'VExD';
      break;

    default:
      $('#entryEquals').val('');
      break;
  }

  $('#entryEquals').val(keyword);
});

解决方案:

参考一: https://en.stackoom.com/question/2hhuU
参考二: https://stackoom.com/question/2hhuU
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部