Here you can find the source of addDays(Date aDate, int days)
Parameter | Description |
---|---|
aDate | Pass date by value. |
days | Number of days to add. |
public static Date addDays(Date aDate, int days)
//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(); } }