Java Day Add addDays(final Date date, final int addDays)

Here you can find the source of addDays(final Date date, final int addDays)

Description

Adds days to the given Date object and returns it.

License

Apache License

Parameter

Parameter Description
date The Date object to add the days.
addDays The days to add.

Return

The resulted Date object.

Declaration

public static Date addDays(final Date date, final int addDays) 

Method Source Code

//package com.java2s;
/**// w ww.  ja  v a 2s. c om
 * Copyright (C) 2007 Asterios Raptis
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

public class Main {
    /**
     * Adds days to the given Date object and returns it. Note: you can add negative values too for
     * get date in past.
     *
     * @param date
     *            The Date object to add the days.
     * @param addDays
     *            The days to add.
     * @return The resulted Date object.
     */
    public static Date addDays(final Date date, final int addDays) {
        final Calendar dateOnCalendar = Calendar.getInstance();
        dateOnCalendar.setTime(date);
        dateOnCalendar.add(Calendar.DATE, addDays);
        return dateOnCalendar.getTime();
    }
}

Related

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