Java Calendar Add addCalendarMonthsToUnixtime(long time, int interval)

Here you can find the source of addCalendarMonthsToUnixtime(long time, int interval)

Description

Add the specified amount of months to the given time.
The day of month will stay the same.

License

Open Source License

Parameter

Parameter Description
time the base-time (in milliseconds) to which the amount of months is added
interval the amount of months to be added

Return

the calculated time in milliseconds

Declaration

public static final long addCalendarMonthsToUnixtime(long time, int interval) 

Method Source Code

//package com.java2s;
/**//ww  w. j av  a2  s .  co m
 * Copyright (c) 2012 Todoroo Inc
 *
 * See the file "LICENSE" for the full license governing this code.
 */

import java.util.Calendar;

public class Main {
    /**
     * Add the specified amount of months to the given time.<br/>
     * The day of month will stay the same.<br/>
     *
     * @param time the base-time (in milliseconds) to which the amount of months is added
     * @param interval the amount of months to be added
     * @return the calculated time in milliseconds
     */
    public static final long addCalendarMonthsToUnixtime(long time, int interval) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(time);
        c.add(Calendar.MONTH, interval);
        return c.getTimeInMillis();
    }
}

Related

  1. add(Date date, int calendarField, int amount)
  2. add(Date inputDate, int interval, int calendarUnit)
  3. add(final Date date, final int calendarField, final int amount)
  4. add2Calendar(Calendar cal, int years, int months, int days, int hours, int minutes, int seconds, int millis)
  5. addCalendarDate(Calendar cal, int date)
  6. addCalendarQuarterOfYear(Calendar cal, int quartersOfYear)
  7. addDate(Calendar baseDate, int addDate)
  8. addDate(Calendar baseDate, int diffDate, TimeZone timezone)
  9. addDate(Date date, int calendarField, int amount)