Java Day Add addDays(Date aDate, int days)

Here you can find the source of addDays(Date aDate, int days)

Description

Add days to a date by value.

License

Apache License

Parameter

Parameter Description
aDate Pass date by value.
days Number of days to add.

Return

A new date object with the days added.

Declaration

public static Date addDays(Date aDate, int days) 

Method Source Code

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

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

public class Main {
    /**/*  ww  w.  ja v  a2 s. c om*/
     * Add days to a date by value.
     *
     * @param aDate Pass date by value.
     * @param days Number of days to add.
     * @return A new date object with the days added.
     */
    public static Date addDays(Date aDate, int days) {
        return addTime(aDate, (24 * days), Calendar.HOUR);
    }

    /**
     * Add time to a date with generic settings.
     *
     * @param aDate A starting date to reference.
     * @param timeToAdd Amount of time to add to starting reference.
     * @param timeUnits Units of time for the timeToAdd field.
     * @return The resultant date.
     */
    public static Date addTime(Date aDate, int timeToAdd, int timeUnits) {
        Calendar cal = GregorianCalendar.getInstance();
        cal.setTime(aDate);
        cal.add(timeUnits, timeToAdd);
        return cal.getTime();
    }
}

Related

  1. addDay(String currentdate, int add_day)
  2. addDay(String d)
  3. addDay(String data)
  4. addDay(String datetime, int day)
  5. addDayInterval(long millis, int dayInterval)
  6. addDays(Date baseDate, int amount, boolean endOfDay)
  7. addDays(Date beginDate, int days)
  8. addDays(Date d, double count)
  9. addDays(Date d, int days)