-
Notifications
You must be signed in to change notification settings - Fork 193
date.setMonth() on a date outputs wrong month #168
Comments
Looks like you filed this in January 30th. Other months will have the same problem, it's just more visible with February. Ex:
|
Thanks for the reply. Is there a suggestion to work around this? |
You can pass setMonth() a day value as a second parameter (I'm assuming you are only interested in the month so day 1 is the simplest), but it will still apply the month parameter first. It does work if you use setFullYear(year, month, day), like so:
|
I also noticed this issue. The workaround described by @vclayton works. Does this only effect February? |
This library is no longer maintained, and this repo is here only for historical interest. |
Hi I'm running into a bit of problem here. It's better explain it by code below.
There seems to be a error with properly setting the month for February.
var timezone = 'America/New_York';
var _tz = timezoneJS.timezone;
_tz.loadingScheme = _tz.loadingSchemes.MANUAL_LOAD;
_tz.loadZoneJSONData('major_cities.json', true);
timezoneJS.timezone._useCache = false;
var date = new timezoneJS.Date(timezone);
console.log('setting month to 1');
date.setMonth(1);
console.log(date);
console.log('setting month to 1');
date.setMonth(1);
console.log(date);
console.log('setting month to 2');
date.setMonth(2);
console.log(date);
console.log('setting month to 3');
date.setMonth(3);
console.log(date);
I'm getting the following output
setting month to 1 <----this is wrong! setting month to 1, but what's returned is 2
2
setting month to 1
1
setting month to 2
2
setting month to 3
3
As you can see, on the initial setMonth(), i'm getting a value of '2' returned. but any subsequent setMonth() are correct.
Do you know why this might be?
Thanks
The text was updated successfully, but these errors were encountered: