Java Date Add addDays(Date target, int days)

Here you can find the source of addDays(Date target, int days)

Description

add Days

License

Open Source License

Declaration

public static final Date addDays(Date target, int days) 

Method Source Code


//package com.java2s;
/*//from   ww w.jav  a 2  s  . co m
 * Copyright 2007 Sun Microsystems, Inc.
 * All rights reserved.  You may not modify, use,
 * reproduce, or distribute this software except in
 * compliance with  the terms of the License at:
 * http://developer.sun.com/berkeley_license.html
 */

import java.util.*;

public class Main {
    public static final Date addDays(Date target, int days) {
        // returns a Date that is the sum of the target Date
        // and the specified number of days;
        // to subtract days from the target Date, the days
        // argument should be negative
        long msPerDay = 1000 * 60 * 60 * 24;
        long msTarget = target.getTime();
        long msSum = msTarget + (msPerDay * days);
        Date result = new Date();
        result.setTime(msSum);

        return result;
    }
}

Related

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