Java Date After getDateAfter(Date date, int days)

Here you can find the source of getDateAfter(Date date, int days)

Description

Get date after/before base date.

License

Open Source License

Parameter

Parameter Description
date a parameter
days a parameter

Return

date

Declaration

public static Date getDateAfter(Date date, int days) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * QMetry Automation Framework provides a powerful and versatile platform to author 
 * Automated Test Cases in Behavior Driven, Keyword Driven or Code Driven approach
 *                //ww w.ja  va2  s  .  co  m
 * Copyright 2016 Infostretch Corporation
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
 * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
 *
 * You should have received a copy of the GNU General Public License along with this program in the name of LICENSE.txt in the root folder of the distribution. If not, see https://opensource.org/licenses/gpl-3.0.html
 *
 * See the NOTICE.TXT file in root folder of this source files distribution 
 * for additional information regarding copyright ownership and licenses
 * of other open source software / files used by QMetry Automation Framework.
 *
 * For any inquiry or need additional information, please contact support-qaf@infostretch.com
 *******************************************************************************/

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

public class Main {
    /**
     * Get date after/before base date. Example:
     * <ol>
     * <li>getDate(baseDate, 5) will return 5 day's date after baseDate
     * <li>getDate(baseDate, -5) will return 5 day's date before baseDate
     * </ol>
     * 
     * @param date
     * @param days
     * @return date
     */
    public static Date getDateAfter(Date date, int days) {
        Calendar cal = getCalendarDate(date);
        cal.add(Calendar.DAY_OF_MONTH, days);
        return cal.getTime();
    }

    public static Calendar getCalendarDate(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal;
    }
}

Related

  1. getAfterDay(Date date, Integer day)
  2. getAfterDayNumber(Date endDate, Date startDate)
  3. getAfterEndDate(Integer day)
  4. getAfterMin(Date date, int min)
  5. getDateAfter(Date d, int day)
  6. getDateAfter(Date date, int increment)
  7. getDateAfterAddition(Date date, int days)
  8. getDateAfterMonths(Date start, int months)
  9. getDateScopeAfterMonth(int year, int month)