new Date() set to 31 december 2014 says 1st december instead

The thing is, when you set a day first, you’re still in the current month, so September. September has only 30 days so:

var dt = new Date(); /* today */
dt.setDate("31"); /* 1st Oct 2014 as should be by spec */
dt.setMonth("11"); /* 1st Dec 2014 */
dt.setFullYear("2014"); /* 1st Dec 2014 */

Leave a Comment