Add the given amount of months to the given calendar. - Java java.util

Java examples for java.util:Month

Description

Add the given amount of months to the given calendar.

Demo Code


//package com.java2s;
import java.util.Calendar;

public class Main {
    public static void main(String[] argv) throws Exception {
        Calendar calendar = Calendar.getInstance();
        int months = 2;
        addMonths(calendar, months);/* ww w.  j  a  v  a  2  s .c  o m*/
    }

    /**
     * Add the given amount of months to the given calendar. The changes are
     * reflected in the given calendar.
     * 
     * @param calendar
     *            The calendar to add the given amount of months to.
     * @param months
     *            The amount of months to be added to the given calendar.
     *            Negative values are also allowed, it will just go back in
     *            time.
     */
    public static void addMonths(Calendar calendar, int months) {
        calendar.add(Calendar.MONTH, months);
    }
}

Related Tutorials