简体   繁体   English

格式已弃用警告-但我正在指定格式

[英]Deprecation warning for format - but I am specifying format

Using moment.js, I keep getting the format warning in the browser console: 使用moment.js,我不断在浏览器控制台中收到格式警告:

Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. 弃用警告:提供的值不是公认的RFC2822或ISO格式。 moment construction falls back to js Date(), which is not reliable across all browsers and versions. 此刻的构建工作归结于js Date(),它在所有浏览器和版本之间都不可靠。 Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. 不建议使用非RFC2822 / ISO日期格式,并将在即将发布的主要版本中将其删除。 Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info. 请参阅http://momentjs.com/guides/#/warnings/js-date/了解更多信息。 Arguments: 参数:

But as far as I can tell, I specified the format as per the docs: 但据我所知,我根据文档指定了格式:

const checkToday = (targetDate)=> {
  return chartData
    .filter(curve => moment(curve.date, "MM-DD-YYYY").isBefore(targetDate, 'day'));
};

if (chartData) {
  // addd # days to today
  const targetDate = moment().add(days, 'days').format('MM-DD-YYYY');
  return checkToday(targetDate);
}

Where is it complaining that I am not specifying the format? 在哪里抱怨我没有指定格式?

The problem is in this line: 问题在这一行:

.filter(curve => moment(curve.date, "MM-DD-YYYY").isBefore(targetDate, 'day'));

You are passing a string to .isBefore that is created in this line: 您正在将字符串传递给在此行中创建的.isBefore

const targetDate = moment().add(days, 'days').format('MM-DD-YYYY');

The format you are using for that string "MM-DD-YYYY" is what moment is complaining about. 您正在抱怨的是该字符串“ MM-DD-YYYY”使用的格式。 Acceptable formats are found here 可以在这里找到可接受的格式

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

相关问题 以字符串格式提供时刻时的 ISO 格式弃用警告 - ISO format deprecation warning when providing moment in string format 即使在转换为 ISO 格式后,Moment js Deprecation 警告也是如此。 我转换成ISO格式还是不行 - Moment js Deprecation warning even after converting to ISO format. I converted into ISO format and still it doesn't work Moment.js 中的弃用警告 - 不是公认的 ISO 格式 - Deprecation warning in Moment.js - Not in a recognized ISO format 使用moment.js排序:弃用警告:提供的值不是可识别的RFC2822或ISO格式 - Sort with moment.js: Deprecation warning: value provided is not in a recognized RFC2822 or ISO format Laravel - 弃用警告:提供的值不是可识别的 RFC2822 或 ISO 格式 - Laravel - Deprecation warning: value provided is not in a recognized RFC2822 or ISO format 为什么我要打印的数据不是表格格式 - Why is the data I am printing not in a table format 我需要验证时间的格式AM | PM - I need to validate the format of time AM|PM 在 javascript 或 momentjs 中获取给定的日期格式(指定格式的字符串) - Get the given date format (the string specifying the format) in javascript or momentjs 有没有办法指定date.js的输入格式? - Is there a way of specifying the format of input of date.js? JavaScript禁止显示日期格式警告 - JavaScript suppress date format warning
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM