Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何避免';弃用警告';在moment.js上?_Javascript_Momentjs - Fatal编程技术网

Javascript 如何避免';弃用警告';在moment.js上?

Javascript 如何避免';弃用警告';在moment.js上?,javascript,momentjs,Javascript,Momentjs,我有多种格式的日期数据,如下所示 20-02-01 22:12:13 2020-02-01(星期五)22:12:13 2020/02/01(星期五)22:12:13 2020/02/01 22:12 我希望将这些格式数据细化为“YYYY/DD/MM hh:MM”格式 因此,我将这些未定义的数据放到了moment.js date = moment(date).format('YYYY-DD-MM HH:mm'); 然后,这个时刻在下面给出了这个警告 deprecation warning: va

我有多种格式的日期数据,如下所示

  • 20-02-01 22:12:13
  • 2020-02-01(星期五)22:12:13
  • 2020/02/01(星期五)22:12:13
  • 2020/02/01 22:12
  • 我希望将这些格式数据细化为“YYYY/DD/MM hh:MM”格式

    因此,我将这些未定义的数据放到了moment.js

    date = moment(date).format('YYYY-DD-MM HH:mm');
    
    然后,这个时刻在下面给出了这个警告

    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)
    
    我可以手动优化,但是。。。我必须将日期数据细化到矩()中,并将数据细化到ISO或RFC2822格式以将其放入矩()中,这一步骤也感觉像是浪费

    请告诉我是否有办法明智地使用矩.js


    提前谢谢你

    无论您是否放置任何格式的数据,都可以避免该警告

    • 20-02-01 22:12:13
    • 2020-02-01(星期五)22:12:13
    • 2020/02/01(星期五)22:12:13
    • 2020/02/01 22:12
    以下代码中没有弃用警告

    date = moment(date,'YYYY-DD-MM HH:mm').format('YYYY-DD-MM HH:mm');
    

    我不能确定这种方法是最好的解决方法,但除非您不需要在放入矩()之前优化数据

    “若要解决此问题,请为传递给矩()的字符串指定一种格式。”-例如
    矩($(“#日期”).val(),'YYYY-MM-DD hh:MM:ss a')
    -您需要在解析时指定格式。如果必须指定给矩()的日期格式,如何处理多个未定义的日期数据?如果我有4种不同格式的日期数据,那么我需要使用开关吗?