Javascript date does not look right when month changes

My eyes should fool me, but when I call setMonth(1) , should the date of this object date be in February? (Today is March 30, 2016)

 x = new Date(); y = new Date(); x.setMonth(1); document.write(x.toString() + '<br>' + y.toString()); 

Results in:

+5
source share
1 answer

No February 30, 2016.

Thus, the date handler correctly changes the date until March 1, 2016.

+10
source

Source: https://habr.com/ru/post/1246078/


All Articles