Java Day Add addDays(Date dt, int numDays)

Here you can find the source of addDays(Date dt, int numDays)

Description

Add a number of days to the given day.

License

Open Source License

Parameter

Parameter Description
dt a parameter
numDays Number of days to add/subtract.

Declaration

public static Date addDays(Date dt, int numDays) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /** Add a number of days to the given day. Can be a negative number.
     * @param dt //from w w w .j  a v  a  2 s  . com
     * @param numDays Number of days to add/subtract.
     * @return
     */
    public static Date addDays(Date dt, int numDays) {
        if (dt == null)
            return null;
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(dt);
        // add one day to this day
        gc.add(Calendar.DATE, numDays);
        return gc.getTime();
    }
}

Related

  1. addDays(Date date, int days)
  2. addDays(Date date, int days)
  3. addDays(Date date, int daysOffset, boolean stripTime)
  4. addDays(Date date, int daysToAdd)
  5. addDays(Date date, int i)
  6. addDays(Date start, int days)
  7. addDays(Date startDate, int numDays)
  8. addDays(Date when, int amount)
  9. addDays(final Date date, final int addDays)