Java Date Adjust adjustDays(Date startingDate, int deltaDays)

Here you can find the source of adjustDays(Date startingDate, int deltaDays)

Description

Takes a Date and moves in the desired amount of days.

License

Apache License

Parameter

Parameter Description
startingDate Date to be altered
deltaDays Number of days to be moved. Use positive integers for a move to the future, and a negative number for a change to the past.

Return

returns the new Date

Declaration

public static Date adjustDays(Date startingDate, int deltaDays) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /**//from ww w  .  j a  v a 2  s .c om
     * Takes a {@link Date} and moves in the desired amount of days.  
     * @param startingDate Date to be altered
     * @param deltaDays Number of days to be moved. Use positive integers for a move to the future, and a negative number for a change to the past.
     * @return returns the new Date
     */
    public static Date adjustDays(Date startingDate, int deltaDays) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(startingDate);
        cal.add(Calendar.DATE, deltaDays);
        return cal.getTime();
    }
}

Related

  1. adjustDate(Date dtDate, int iYears, int iMonths, int iDays, int iHours, int iMinutes, int iSeconds)
  2. adjustHour(Date dt, int hour)
  3. adjustHourAndMinute(Date n)
  4. adjustTime(Date date, int hour, int minute, int second)
  5. adjustToDayStartAndEnd(Date from, Date to)