My date is in the format of 2011-04-01. When I run the below code the following results.
var dateParts = '2011-04-01'.split('-'); dateParts[0] = parseInt(dateParts[0]); dateParts[1] = parseInt(dateParts[1]); dateParts[2] = parseInt(dateParts[2]); console.log(dateParts); for (i = 0; i <= 13; i++) { var thisDate = new Date(dateParts[0], dateParts[1], dateParts[2] + i); console.log(thisDate); } Result:
[2011, 4, 1] Date {Sun May 01 2011 00:00:00 GMT-0400 (Eastern Daylight Time)} Date {Mon May 02 2011 00:00:00 GMT-0400 (Eastern Daylight Time)} Date {Tue May 03 2011 00:00:00 GMT-0400 (Eastern Daylight Time)} Date {Wed May 04 2011 00:00:00 GMT-0400 (Eastern Daylight Time)} Date {Thu May 05 2011 00:00:00 GMT-0400 (Eastern Daylight Time)} Date {Fri May 06 2011 00:00:00 GMT-0400 (Eastern Daylight Time)} Date {Sat May 07 2011 00:00:00 GMT-0400 (Eastern Daylight Time)} Date {Sun May 08 2011 00:00:00 GMT-0400 (Eastern Daylight Time)} Date {Mon May 09 2011 00:00:00 GMT-0400 (Eastern Daylight Time)} Date {Tue May 10 2011 00:00:00 GMT-0400 (Eastern Daylight Time)} Date {Wed May 11 2011 00:00:00 GMT-0400 (Eastern Daylight Time)} Date {Thu May 12 2011 00:00:00 GMT-0400 (Eastern Daylight Time)} Date {Fri May 13 2011 00:00:00 GMT-0400 (Eastern Daylight Time)} Date {Sat May 14 2011 00:00:00 GMT-0400 (Eastern Daylight Time)} The date I split and the number I am giving the Date object are in April, why is it generating a date in May? I'm a bit new to JS so there may be something obvious I am missing. Any assistance or suggestions for improvements would be appreciated.