Are you trying to get 1 month from now? If so, what you get is right. 1 Month from May 31 - July 1, and not June 30. If you want it to go only to the second month only depending on the number of days in that month:
Example: Jan 31st 2014 -> Feb 28th 2014 or the case you mentioned, you can use a little hack to use minus the current days and the number of days in the next month to keep you in the same month:
// Assume its yesterday var date = new Date(2014, 4, 31); // Get the current date var currentDate = date.getDate(); // Set to day 1 to avoid forward date.setDate(1); // Increase month by 1 date.setMonth(date.getMonth() + 1); // Get max
source share