[英]How to avoid 'deprecation waring' on moment.js?
I have multiple format of date data like these below.我有多种格式的日期数据,如下所示。
I want refine those format data to 'YYYY/DD/MM hh:mm' format.我想将这些格式数据细化为 'YYYY/DD/MM hh:mm' 格式。
thus i put those unrefined data to moment.js!因此我将那些未精炼的数据放到 moment.js 中!
date = moment(date).format('YYYY-DD-MM HH:mm');
then moment gave this warning below.然后时刻在下面给出了这个警告。
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: 2020/02/03 22:52:28, _f: undefined, _strict: undefined, _locale: [object Object]
Error
at Function.createFromInputFallback (/Users/loganlee/project/portfolio/back_stastics/backend/node_modules/moment/moment.js:320:98)
at configFromString (/Users/loganlee/project/portfolio/back_stastics/backend/node_modules/moment/moment.js:2385:15)
at configFromInput (/Users/loganlee/project/portfolio/back_stastics/backend/node_modules/moment/moment.js:2611:13)
at prepareConfig (/Users/loganlee/project/portfolio/back_stastics/backend/node_modules/moment/moment.js:2594:13)
at createFromConfig (/Users/loganlee/project/portfolio/back_stastics/backend/node_modules/moment/moment.js:2561:44)
at createLocalOrUTC (/Users/loganlee/project/portfolio/back_stastics/backend/node_modules/moment/moment.js:2648:16)
at createLocal (/Users/loganlee/project/portfolio/back_stastics/backend/node_modules/moment/moment.js:2652:16)
at hooks (/Users/loganlee/project/portfolio/back_stastics/backend/node_modules/moment/moment.js:12:29)
at /Users/loganlee/project/portfolio/back_stastics/backend/src/PreProcessor/index.js:263:15
at processTicksAndRejections (internal/process/task_queues.js:97:5)
I can do refine manually but... the step that i have to refine date data to put into moment() and refine the data to ISO or RFC2822 format to put that into moment() also feels like wasting.我可以手动进行优化,但是……我必须将日期数据精炼到 moment() 并将数据精炼为 ISO 或 RFC2822 格式以将其放入 moment() 的步骤也感觉像是在浪费。
Please tell me if there is a way to use moment.js in wise way!请告诉我是否有一种明智的方式使用 moment.js 的方法!
Thank you in advance!先感谢您!
You can avoid that warning whether you put any format of data无论您放置任何格式的数据,您都可以避免该警告
there is no deprecation warning with below code.以下代码没有弃用警告。
date = moment(date,'YYYY-DD-MM HH:mm').format('YYYY-DD-MM HH:mm');
I can't sure this way is the best to solve but unless you don't need to refine data before put into moment()!我不确定这种方法是最好的解决方法,但除非您不需要在放入 moment() 之前优化数据!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.