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')


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM