Can anyone tell me why the month is March instead of Feb, if I enter a year after 2020? Tested on Windows 10, Chrome & Edge
const date = new Date()
date.setFullYear("2021")
date.setMonth("1") // February
date.setDate("23")
console.log(date)
The result of console log...
Tue Mar 23 2021 22:38:13 GMT+0800 (Singapore Standard Time)
The following shows the correct month though...
var event = new Date('August 19, 2025 23:15:30');
event.setMonth(1);
console.log(event);
Result is
Wed Feb 19 2025 23:15:30 GMT+0800 (Singapore Standard Time)
Please Note: If I use year 2020 or below, the return values are correct. The answer needs to explain this anamoly...
d.setFullYear(2021, 1, 23)
. :-)