gpt4 book ai didi

javascript - Momentjs 弃用错误和不同的浏览器功能

转载 作者:行者123 更新时间:2023-12-03 04:13:06 25 4
gpt4 key购买 nike

我收到此错误:

Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments:
[0] _isAMomentObject: true, _isUTC: false, _useUTC: false, _l: undefined, _i: 1-June-2017, _f: undefined, _strict: undefined, _locale: [object Object]
Error
at Function.createFromInputFallback (http://localhost/client.min.js:46682:95)
at configFromString (http://localhost/client.min.js:48540:12)
at configFromInput (http://localhost/client.min.js:48909:10)
at prepareConfig (http://localhost/client.min.js:48892:10)
at createFromConfig (http://localhost/client.min.js:48859:41)
at createLocalOrUTC (http://localhost/client.min.js:48946:13)
at createLocal (http://localhost/client.min.js:48950:13)
at Moment.isBefore (http://localhost/client.min.js:49517:49)
at http://localhost/client.min.js:46163:87
at Array.map (native)

因为代码被最小化,所以我无法确切地看出是什么导致了它,并且有很多代码,但它可能位于以下任何一个中:

    this.state = {
bookedDays: this.props.bookedDays,
today: this.props.value != "" ? moment.unix(this.props.value.substr(0, this.props.value.indexOf('|'))/1000) : moment(),
selectedFromDate: this.props.value != "" ? moment.unix(this.props.value.substr(0, this.props.value.indexOf('|'))/1000) : moment(),
selectedToDate: this.props.value != "" ? moment.unix(this.props.value.substr(this.props.value.indexOf('|')+1)/1000) : moment(),
whichDate: 0
};



var liClasses = classNames({
'whiteDate': this.state.whichDate == 0 && ((this.state.selectedFromDate.isBefore(date, 'day') && this.state.selectedToDate.isAfter(date, 'day')) || this.state.selectedFromDate.isSame(date, 'day') || this.state.selectedToDate.isSame(date, 'day'))
});

请注意,该代码仅适用于 Chrome,在正确填充类方面,Firefox、IE 和 Edge 似乎都不喜欢它。

最佳答案

问题可能是代码第二部分中的date是一个字符串,moment(String)无法识别该格式。功能。

您应该使用moment(String, String) 。从错误消息来看,您似乎正在传递 1-June-2017 作为输入值,因此您必须使用:

moment(date, 'D-MMMM-YYYY')

您的代码将如下所示:

var liClasses = classNames({
'whiteDate': this.state.whichDate == 0 &&
((this.state.selectedFromDate.isBefore(moment(date, 'D-MMMM-YYYY'), 'day') &&
this.state.selectedToDate.isAfter(moment(date, 'D-MMMM-YYYY'), 'day')) ||
this.state.selectedFromDate.isSame(moment(date, 'D-MMMM-YYYY'), 'day') ||
this.state.selectedToDate.isSame(moment(date, 'D-MMMM-YYYY'), 'day'))
});

关于javascript - Momentjs 弃用错误和不同的浏览器功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44246246/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com