Moment Js Add Function Is Not Working
Literally, moment().add() is not working in my js code. In this code, I used moment add twice. First is checkquarter, which is added 30 minutes to theDate variable. Second is endt
Solution 1:
You should clone theDate
into checkQuarter
as Moments are mutable.
https://momentjs.com/docs/#/manipulating/
this means that var checkquarter = theDate.add(30, 'minutes');
is changing theDate
and checkQuarter
is just another reference to theDate
.
Have a look at the console when you run the following :
var theDate = moment("1995-12-25 14:00");
console.log(theDate.toString());
var newDate = theDate.add(10, "minutes");
console.log(theDate.toString());
console.log(newDate.toString());
var anotherDate = moment(theDate);
anotherDate.add(10, "minutes");
console.log(anotherDate.toString());
console.log(theDate.toString());
Post a Comment for "Moment Js Add Function Is Not Working"