Java Time Add addTime(Date aDate, int timeToAdd, int timeUnits)

Here you can find the source of addTime(Date aDate, int timeToAdd, int timeUnits)

Description

Add time to a date with generic settings.

License

Apache License

Parameter

Parameter Description
aDate A starting date to reference.
timeToAdd Amount of time to add to starting reference.
timeUnits Units of time for the timeToAdd field.

Return

The resultant date.

Declaration

public static Date addTime(Date aDate, int timeToAdd, int timeUnits) 

Method Source Code

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

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

public class Main {
    /**//from ww w. jav a2 s . c o m
     * Add time to a date with generic settings.
     *
     * @param aDate A starting date to reference.
     * @param timeToAdd Amount of time to add to starting reference.
     * @param timeUnits Units of time for the timeToAdd field.
     * @return The resultant date.
     */
    public static Date addTime(Date aDate, int timeToAdd, int timeUnits) {
        Calendar cal = GregorianCalendar.getInstance();
        cal.setTime(aDate);
        cal.add(timeUnits, timeToAdd);
        return cal.getTime();
    }
}

Related

  1. addTime(Date aDate, int timeToAdd, int timeUnits)
  2. addTime(Date baseDate, int amount, int datePart)
  3. addTime(Date current, Date toadd)
  4. addTime(Date date, Date addTime)
  5. addTime(Date date, int field, int value)