美文网首页
moment警告报错

moment警告报错

作者: any_5637 | 来源:发表于2020-07-19 10:52 被阅读0次

如何处理 moment Deprecation warning: value provided is not in a recognized RFC2822 or ISO format

问题描述

当使用 moment 进行时间格式转换时,遇到如下报错:
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.

复现方式:

    // date为当原时间为非法参数时
    transformRequest: val => (val ? moment(val).format('YYYY-MM-DD') : null),

解决方法

方法一

增加时间的构造参数

    const source_date = '2019-05-06`;
    
    moment(source_date, 'YYYY-MM-DD').format('YYYYMMDD');

方法二

关闭提示

    // Suppress the warnings
    const moment = require('moment');
    moment.suppressDeprecationWarnings = true;

方法三

    moment(new Date("27/04/2016")).format('YYYYMMDD')

相关文章

网友评论

      本文标题:moment警告报错

      本文链接:https://www.haomeiwen.com/subject/amboxktx.html