Java Date Add addDays(Date dateToAdd, int numberOfDay)

Here you can find the source of addDays(Date dateToAdd, int numberOfDay)

Description

Add given number of days to a date.

License

Open Source License

Parameter

Parameter Description
dateToAdd The date
numberOfDay The number of days to add

Return

new date

Declaration

private static Date addDays(Date dateToAdd, int numberOfDay) 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    /**/*  w w w  . j a v  a  2s.c  o m*/
     * Add given number of days to a date.
     *
     * @param dateToAdd  The date
     * @param numberOfDay The number of days to add
     * @return new date
     */
    private static Date addDays(Date dateToAdd, int numberOfDay) {
        if (dateToAdd == null) {
            throw new IllegalArgumentException("Date can't be null!");
        }
        Calendar tempCal = Calendar.getInstance();
        tempCal.setTime(dateToAdd);
        tempCal.add(Calendar.DATE, numberOfDay);
        return tempCal.getTime();
    }
}

Related

  1. addDateDay(int day)
  2. addDateParam(String dtstr, boolean start, List where)
  3. addDates(Date startDate, int days)
  4. addDay(Date date, int days)
  5. addDays(Date date1, long days)
  6. addDays(Date target, int days)
  7. addDays(Date when, int amount)
  8. addDays(int count, Calendar timestamp)
  9. addDaysToCurrentDate(Integer dayIncrement)