Java Date After daysAfter(Date dateInst, int numDays)

Here you can find the source of daysAfter(Date dateInst, int numDays)

Description

Method to return a Date instance which is exactly numDays days after the point in time designated by the input Date

License

Open Source License

Parameter

Parameter Description
dateInst - instance of Date
numDays - positive integer

Return

- instance of Date as described

Declaration

public static Date daysAfter(Date dateInst, int numDays) 

Method Source Code

//package com.java2s;
/*/* w  w  w. j  ava  2 s .c  o m*/
    
 Copyright IBM Corp. 2012, 2016
 This file is part of Anomaly Detection Engine for Linux Logs (ADE).

 ADE is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 ADE is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with ADE.  If not, see <http://www.gnu.org/licenses/>.
    
 */

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

public class Main {
    /**
     * Method to return a Date instance which is exactly numDays
     * days after the point in time designated by the input Date
     *  
     * @param dateInst - instance of Date
     * @param numDays  - positive integer
     * @return - instance of Date as described
     */
    public static Date daysAfter(Date dateInst, int numDays) {

        if ((numDays <= 0) || (dateInst == null)) {
            throw new IllegalArgumentException();
        }
        final Calendar cal = new GregorianCalendar();
        cal.setTime(dateInst);
        cal.add(Calendar.DAY_OF_YEAR, numDays);
        return cal.getTime();

    }
}

Related

  1. afterMonth(Date dateTime)
  2. afterOneDay(Date depdt)
  3. dateAfter(Date date, int years, int months)
  4. dateAfter(Date origDate, int amount, int timeUnit)
  5. dateAfterNMonths(Date dt, int n)
  6. getAfter(Date comparedDate, int cursor, String unit)
  7. getAfterDay(Date date, int afterDays)
  8. getAfterDay(Date date, Integer day)
  9. getAfterDayNumber(Date endDate, Date startDate)