Java Date Add addDate(Date date, int noOfDays)

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

Description

Add no of days to a given date, pass negative number if past or to substract date.

License

Open Source License

Parameter

Parameter Description
date Date from which addtion or subtraction to be done.
noOfDays number of days to be added or substracted.

Return

Date after addition or subtraction.

Declaration

public static Date addDate(Date date, int noOfDays) 

Method Source Code

//package com.java2s;

import java.util.Calendar;

import java.util.Date;

public class Main {
    /**//  w w  w  .j a  v a2  s .c o m
     * Add no of days to a given date, pass negative number if past or to substract date.
     * @param date Date from which addtion or subtraction to be done.
     * @param noOfDays number of days to be added or substracted.
     * @return Date after addition or subtraction.
     */
    public static Date addDate(Date date, int noOfDays) {
        Calendar c1 = Calendar.getInstance();
        c1.setTime(date);
        c1.add(Calendar.DATE, noOfDays);
        return c1.getTime();
    }
}

Related

  1. addCertainTime(java.util.Date date, double hours)
  2. addDate(Date date, int add)
  3. addDate(Date date, int amount, int type)
  4. addDate(Date date, int field, int add)
  5. addDate(Date date, int k)
  6. addDate(Date date, int years, int months, int days)
  7. addDate(Date date, String unit, int quantity)
  8. addDate(int field, int amount)
  9. addDate(java.util.Date date, int day)