This only occurs with the setMonth() method and none of the other set*() methods.
Here's an example of what I mean:
var date = new Date();
date.getTimezoneOffset(); // -60
date.setMonth(5);
date.getTimezoneOffset(); // -120
Is this expected behavior? There's nothing mentioned about this on MDN.
The getTimezoneOffset method returns a different value during DST, and in month 5 the DST is different than now.
The time zone offset returned is the one that applies for the Date that it's called on. Where the host system is configured for daylight saving, the offset will change depending on the date and time that the Date represents and that daylight saving applies.
var date = new Date();
console.log(date.getTimezoneOffset());
date.setMonth(0);
console.log(date.getTimezoneOffset());
date.setMonth(5);
console.log(date.getTimezoneOffset());
btw, if you will run this code during June - you will see that there is no difference :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With