[英]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.