Here you can find the source of addDaysToDate(final Date d, final int days)
Parameter | Description |
---|---|
d | date to be adjusted |
days | number of days |
public static Date addDaysToDate(final Date d, final int days)
//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); } }