error - momentjs - Deprecation warning: value provided is not in a recognized RFC2822 or ISO format
error - momentjs - Deprecation warning: value provided is not in a recognized RFC2822 or ISO format
问题
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.
复现方式
const datetime = 'abcde`; // 当原时间为非法参数时 moment(datetime).format('YYYYMMDD');
解决方法
方法一
增加时间的构造参数
const datetime = 'abcde`; // 当原时间为非法参数时 moment(datetime).format('YYYYMMDD');
方法二
关闭提示
// Suppress the warnings const moment = require('moment'); moment.suppressDeprecationWarnings = true;
方法三
moment(new Date("27/04/2016")).format('YYYYMMDD')
Lee2
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步