2015-01-03 13 views
9

我越來越Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to https://github.com/moment/moment/issues/1407 for more info. 但我是新手我無法弄清楚如何解決它,以便上述消息消失。 我認爲問題在於這兩條線,但我不確定。瞬間JS:棄用警告:時刻施工回落到js日期。這是沮喪,將在即將到來的主要版本中刪除

var nextMonth = moment(moment(year + "-" + month + "-1")).add(1, "months").format("MM"); 
var nextYear = moment(moment(year + "-" + month + "-1")).add(1, "months").format("YYYY"); 

我已經檢查https://github.com/moment/moment/issues/1407Deprecation warning: moment construction falls back to js Date但也似乎對我的問題的工作。

我想知道在這個計算中,我應該告訴格式,或者至少如何以正確的格式進行計算,這樣警告消失。

提前致謝!

+2

參考http://stackoverflow.com/questions/23263380/deprecation-warning-moment-construction-falls-back-to-js-date – murli2308

回答

12

其實我發現了這個問題。

通過在兩個計算中添加新的Date(),它再次標準化。

var nextMonth = moment(new Date(year, month - 1, 1)).add(1, "months").format("MM"); 
var nextYear = moment(new Date(year, month - 1, 1)).add(1, "months").format("YYYY"); 

我希望它能幫助別人!

+0

感謝您的提示!編輯。 –

+0

這是非常好的答案 –

+1

參考http://stackoverflow.com/questions/23263380/deprecation-warning-moment-construction-falls-back-to-js-date – murli2308

相關問題