Add Months to a Gregorian Calendar.

@param cal The XMLGregorianCalendar source
@param amount The amount of months. Can be a negative Integer to
substract.
@return A XMLGregorianCalendar with the new Date
547386
public XMLGregorianCalendar addMonths(final XMLGregorianCalendar cal, final int amount) {
        XMLGregorianCalendar to = buildXMLGregorianCalendarDate(cal);
        // Add amount of months
        to.add(addMonths(amount));
        return to;
    }
1206316
public long add(long instant, long months) {
        int i_months = (int)months;
        if (i_months == months) {
            return add(instant, i_months);
        }

        // Copied from add(long, int) and modified slightly:

        long timePart = iChronology.getMillisOfDay(instant);

        int thisYear = iChronology.getYear(instant);
        int thisMonth = iChronology.getMonthOfYear(instant, thisYear);

        long yearToUse;
        long monthToUse = thisMonth - 1 + months;
        if (monthToUse >= 0) {
            yearToUse = thisYear + (monthToUse / iMax);
            monthToUse = (monthToUse % iMax) + 1;
        } else {
            yearToUse = thisYear + (monthToUse / iMax) - 1;
            monthToUse = Math.abs(monthToUse);
            int remMonthToUse = (int)(monthToUse % iMax);
            if (remMonthToUse == 0) {
                remMonthToUse = iMax;
            }
            monthToUse = iMax - remMonthToUse + 1;
            if (monthToUse == 1) {
                yearToUse += 1;
            }
        }

        if (yearToUse < iChronology.getMinYear() ||
            yearToUse > iChronology.getMaxYear()) {

            throw new IllegalArgumentException
                ("Magnitude of add amount is too large: " + months);
        }

        int i_yearToUse = (int)yearToUse;
        int i_monthToUse = (int)monthToUse;

        int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
        int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
        if (dayToUse > maxDay) {
            dayToUse = maxDay;
        }

        long datePart =
            iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
        return datePart + timePart;
    }
8783
public XMLGregorianCalendar newGMonthDay(int month, int day) {
        XMLGregorianCalendar cal=dataFactory.newXMLGregorianCalendar();
        cal.setMonth(month);
        cal.setDay(day);
        return cal;
    }
815089
public static Date addMonths(Date date, int numOfMonths) {
		Calendar instance = Calendar.getInstance();
		instance.setTime(date);
		instance.add(Calendar.MONTH, numOfMonths);
		return instance.getTime();
	}
402656
public static Date addDay(String date, int amount) throws ParseException {
        return add(date, Calendar.DATE, amount);
    }
383134
public static Date addDay(Date date, int amount) {
        return add(date, Calendar.DATE, amount);
    }
496721
public static int addMonths(int date, int m) {
		int y0 = (int) DateTimeUtils.unixDateExtract(TimeUnitRange.YEAR, date);
		int m0 = (int) DateTimeUtils.unixDateExtract(TimeUnitRange.MONTH, date);
		int d0 = (int) DateTimeUtils.unixDateExtract(TimeUnitRange.DAY, date);
		int y = m / 12;
		y0 += y;
		m0 += m - y * 12;
		int last = lastDay(y0, m0);
		if (d0 > last) {
			d0 = 1;
			if (++m0 > 12) {
				m0 = 1;
				++y0;
			}
		}
		return DateTimeUtils.ymdToUnixDate(y0, m0, d0);
	}
1251576
public static Calendar addMonths(Calendar origin, int value) {
        Calendar cal = sync((Calendar) origin.clone());
        cal.add(Calendar.MONTH, value);
        return sync(cal);
    }
567222
private void increment(final Calendar cal) {
        // initialise interval..
        final int calInterval = (getInterval() >= 1) ? getInterval() : 1;
        cal.add(calIncField, calInterval);
    }
662340
public void add(Calendar cal) {
    // Avoid precision loss
    // Be aware postgres doesn't return more than 60 seconds - no overflow can happen
    final int microseconds = (int) (getSeconds() * 1000000.0);
    final int milliseconds = (microseconds + ((microseconds < 0) ? -500 : 500)) / 1000;

    cal.add(Calendar.MILLISECOND, milliseconds);
    cal.add(Calendar.MINUTE, getMinutes());
    cal.add(Calendar.HOUR, getHours());
    cal.add(Calendar.DAY_OF_MONTH, getDays());
    cal.add(Calendar.MONTH, getMonths());
    cal.add(Calendar.YEAR, getYears());
  }
363126
public XMLGregorianCalendar newGYear(int year) {
        XMLGregorianCalendar cal=dataFactory.newXMLGregorianCalendar();
        cal.setYear(year);
        return cal;
    }
456861
public static Date addMonth(String date, int amount) throws ParseException {
        return add(date, Calendar.MONTH, amount);
    }
1344793
public static Date addMonth(Date date, int amt) {
		return addDateField(date,Calendar.MONTH,amt);
	}
451708
public static XMLGregorianCalendar convertDateToXMLGregorianCalendar(final Date date) {
        try {
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTime(date);
            XMLGregorianCalendar calXml = DatatypeFactory.newInstance().newXMLGregorianCalendar(
                    cal.get(Calendar.YEAR),
                    cal.get(Calendar.MONTH) + 1,
                    cal.get(Calendar.DAY_OF_MONTH),
                    cal.get(Calendar.HOUR_OF_DAY),
                    cal.get(Calendar.MINUTE),
                    cal.get(Calendar.SECOND),
                    cal.get(Calendar.MILLISECOND),
                    0);
            return calXml;
        } catch (DatatypeConfigurationException e) {
            throw new SwidException("Cannot convert date", e);
        }
    }
1355158
public void setMonth(int month) {
		calendar.set(Calendar.MONTH, month);
		int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
		
		int adjustedDay = day;
		if (day > maxDays) {
			adjustedDay = maxDays;
			setDay(adjustedDay);
		}

		drawDays();
	}
649159
public XMLGregorianCalendar buildXMLGregorianCalendarDate(XMLGregorianCalendar cal) {
        XMLGregorianCalendar result = null;
        if (cal != null) {
            result = newXMLGregorianCalendar(cal.getDay(), cal.getMonth(), cal.getYear());
        }
        return result;
    }
968179
public static Date addMonth(Date date1, int addMonth) {
        Date resultDate = null;
        Calendar c = Calendar.getInstance();
        c.setTime(date1); // 设置当前日期
        c.add(Calendar.MONTH, addMonth); // 日期加1
        resultDate = c.getTime(); // 结果
        return resultDate;
    }