Moment JS: Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release
Actually I found the problem.
By just adding new Date() to both calculations, it normalized again.
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");
I hope it help others!
Deisy Laymi
Updated on July 24, 2022Comments
-
Deisy Laymi almost 2 years
I'm getting
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.
But I'm a newbie I cannot figure out how to fix it so the above message disappear. I think the problem lies in these two lines but I'm not sure.var nextMonth = moment(moment(year + "-" + month + "-1")).add(1, "months").format("MM"); var nextYear = moment(moment(year + "-" + month + "-1")).add(1, "months").format("YYYY");
I have already checked https://github.com/moment/moment/issues/1407 and Deprecation warning: moment construction falls back to js Date but neither seems to work on my problem.
I would like to know where in this calculation I should tell the format to the moment or at least how to make this calculations in the right format so the warning disappears.
Thanks in advance!
-
Deisy Laymi over 9 yearsThanks for the tip! Edited.
-
arjun kori about 8 yearsthat was very good answer
-
murli2308 about 8 years
-
Ben almost 8 yearsThe comment thread in the issue has a pretty good explanation as well, now: github.com/moment/moment/issues/1407
-
Panayiotis Georgiou over 3 yearsMoment’s usage is so widespread that it’s impossible to deprecate the current version over time. Check out this [post][1] on alternative options Migrating away from moment.js panayiotisgeorgiou.net/migrating-away-from-moment-js