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

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

Description

This method allows you to add to a java.util.Date returning a Date instead of void like the Calendar does

License

Open Source License

Parameter

Parameter Description
date The date to modify
calendarField The static field from java.util.Calendar to add
numberToAdd The number to add

Return

Date

Declaration

public static Date addDate(Date date, int calendarField, int numberToAdd) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/* ww  w  .  java  2 s.  co  m*/
     * This method allows you to add to a java.util.Date returning a Date
     * instead of void like the Calendar does
     * 
     * @param date
     *            The date to modify
     * @param calendarField
     *            The static field from java.util.Calendar to add
     * @param numberToAdd
     *            The number to add
     * @return Date
     */
    public static Date addDate(Date date, int calendarField, int numberToAdd) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(calendarField, numberToAdd);
        return c.getTime();
    }
}

Related

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