Java Calendar Add getWithDaysAdded( GregorianCalendar originalDate, int days)

Here you can find the source of getWithDaysAdded( GregorianCalendar originalDate, int days)

Description

Returns a new GregorianCalendar instance that is the specified value plus the specified number of days added.

License

Open Source License

Parameter

Parameter Description
originalDate the original date to start from
days the number of days to add

Return

the new date

Declaration

public static GregorianCalendar getWithDaysAdded(
        GregorianCalendar originalDate, int days) 

Method Source Code

//package com.java2s;
/**/*  w w w .j  a  va 2  s . c o m*/
 * Copyright (c) 2010 Martin Geisse
 *
 * This file is distributed under the terms of the MIT license.
 */

import java.util.Calendar;

import java.util.GregorianCalendar;

public class Main {
    /**
     * Returns a new {@link GregorianCalendar} instance that is the specified value plus the
     * specified number of days added. The original date is left unchanged. The result has
     * the same time-of-day as the original.
     * @param originalDate the original date to start from
     * @param days the number of days to add
     * @return the new date
     */
    public static GregorianCalendar getWithDaysAdded(
            GregorianCalendar originalDate, int days) {
        GregorianCalendar newDate = (GregorianCalendar) originalDate
                .clone();
        newDate.add(Calendar.DAY_OF_MONTH, days);
        return newDate;
    }
}

Related

  1. appendTime(Calendar value, StringBuffer dateString)
  2. appendTimeZone(Calendar calendar, StringBuffer dateString)
  3. cloneAndAdd(Calendar source, int field, int amount)
  4. getDayOfAddDay(final Calendar calendar, final int day)
  5. getStartDateForLogQuery(int calendarField, int amountToAdd)
  6. moveToCalendarSecondJustAdded(Calendar cal, int seconds)