Java Day Add addDaysToDate(final Date d, final int days)

Here you can find the source of addDaysToDate(final Date d, final int days)

Description

Adds days to a Date.

License

Apache License

Parameter

Parameter Description
d date to be adjusted
days number of days

Return

adjusted date

Declaration

public static Date addDaysToDate(final Date d, final int days) 

Method Source Code


//package com.java2s;
/*// ww  w .  j av a2 s  .c  om
 * Copyright 2014 Scott J. Johnson (http://scottjjohnson.com)
 *
 * 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;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class Main {
    private static final TimeZone exchangeTZ = TimeZone.getTimeZone("America/New_York");

    /**
     * Adds days to a Date.
     *
     * @param d    date to be adjusted
     * @param days number of days
     *
     * @return adjusted date
     */
    public static Date addDaysToDate(final Date d, final int days) {

        Calendar cal = getStockExchangeCalendar();
        cal.setTime(d);

        cal.add(Calendar.DAY_OF_MONTH, days);

        return cal.getTime();
    }

    /**
     * Gets a reference to a Calendar object with the right time zone for the NYSE.
     *
     * @return Calendar in the stock exchange time zone
     */
    public static Calendar getStockExchangeCalendar() {
        return new GregorianCalendar(exchangeTZ);
    }
}

Related

  1. addDaysByFormatter(int days, String dateFormat)
  2. addDaysDate(final java.util.Date date1, final int nbdays)
  3. addDaysOnDate(final Date date, final int numberOfDays)
  4. addDaysToDate(Date date, int numDays)
  5. addDaysToDate(Date date, int value)
  6. addDaysToDate(String s, int day, String format)
  7. addDayString5(Date date, int day)
  8. addDayToString(String strDate, int days)
  9. addOneDay(String strDate)