Java Calendar Add add(Date date, int calendarField, int amount)

Here you can find the source of add(Date date, int calendarField, int amount)

Description

add

License

Apache License

Parameter

Parameter Description
date a parameter
calendarField a parameter
amount a parameter

Return

the date after modify

Declaration

public static Date add(Date date, int calendarField, int amount) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**/* w ww  . ja  v  a 2  s  . co  m*/
     *
     * @param date
     * @param calendarField
     * @param amount
     * @return the date after modify
     * @author Mei Xianzhi
     */
    public static Date add(Date date, int calendarField, int amount) {
        if (date == null) {
            throw new IllegalArgumentException("The date must not be null");
        } else {
            Calendar c = Calendar.getInstance();
            c.setTime(date);
            c.add(calendarField, amount);
            return c.getTime();
        }
    }
}

Related

  1. add(Calendar calendar, int calendarField, int amount)
  2. add(Date _date, int _calendarField, int _amount)
  3. add(Date inputDate, int interval, int calendarUnit)
  4. add(final Date date, final int calendarField, final int amount)
  5. add2Calendar(Calendar cal, int years, int months, int days, int hours, int minutes, int seconds, int millis)
  6. addCalendarDate(Calendar cal, int date)