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

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

Description

add Date

License

Apache License

Declaration

private static Date addDate(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 {
    private static Date addDate(Date date, int calendarField, int amount) {
        assertDateParamsRequired(date);/*from  w  w  w  .  ja  v  a2 s.  co  m*/

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(calendarField, amount);
        return c.getTime();
    }

    private static void assertDateParamsRequired(Date... dates) {
        for (Date date : dates) {
            if (date == null) {
                throw new IllegalArgumentException("The Date type parameters are required.");
            }
        }
    }
}

Related

  1. addCalendarDate(Calendar cal, int date)
  2. addCalendarMonthsToUnixtime(long time, int interval)
  3. addCalendarQuarterOfYear(Calendar cal, int quartersOfYear)
  4. addDate(Calendar baseDate, int addDate)
  5. addDate(Calendar baseDate, int diffDate, TimeZone timezone)
  6. addDate(Date date, int calendarField, int numberToAdd)
  7. addDayOffset(final Calendar date, long offset)
  8. addDays(Calendar aTarget, int aAddDays)
  9. addDays(Calendar calendar, int days)