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

Java examples for java.util:Day

Description

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

Demo Code

/**//from  ww  w  .  j  a  v  a2s.  c  o m
 * Copyright (c) 2010 Martin Geisse
 *
 * This file is distributed under the terms of the MIT license.
 */
//package com.java2s;
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 Tutorials