如何處理 moment Deprecation warning: value provided is not in a recognized RFC2822 or ISO format
問題描述
當(dāng)使用 moment 進(jìn)行時(shí)間格式轉(zhuǎn)換時(shí)窿锉,遇到如下報(bào)錯(cuò):
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.
復(fù)現(xiàn)方式:
// date為當(dāng)原時(shí)間為非法參數(shù)時(shí)
transformRequest: val => (val ? moment(val).format('YYYY-MM-DD') : null),
解決方法
方法一
增加時(shí)間的構(gòu)造參數(shù)
const source_date = '2019-05-06`;
moment(source_date, 'YYYY-MM-DD').format('YYYYMMDD');
方法二
關(guān)閉提示
// Suppress the warnings
const moment = require('moment');
moment.suppressDeprecationWarnings = true;
方法三
moment(new Date("27/04/2016")).format('YYYYMMDD')