Java Calendar Add add2Calendar(Calendar cal, int years, int months, int days, int hours, int minutes, int seconds, int millis)

Here you can find the source of add2Calendar(Calendar cal, int years, int months, int days, int hours, int minutes, int seconds, int millis)

Description

Adds the specified values to the values to the specified Calendar instance and returns the result.

License

MIT License

Parameter

Parameter Description
cal a Calendar instance to modify.
years the number of years to add.
months the number of months to add.
days the number of days to add.
hours the number of hours to add.
minutes the number of minutes to add.
seconds the number of seconds to add.
millis the number of milliseconds to add.

Return

the updated Calendar instance.

Declaration


public static Calendar add2Calendar(Calendar cal, int years, int months, int days, int hours, int minutes,
        int seconds, int millis)

    

Method Source Code

//package com.java2s;
/*/*from   w w w  .j av a 2s. c  o m*/
 * Copyright (c) 2015-2016 QuartzDesk.com.
 * Licensed under the MIT license (https://opensource.org/licenses/MIT).
 */

import java.util.Calendar;

public class Main {
    /**
     * Adds the specified values to the values to the specified Calendar instance and returns
     * the result.
     *
     * @param cal     a Calendar instance to modify.
     * @param years   the number of years to add.
     * @param months  the number of months to add.
     * @param days    the number of days to add.
     * @param hours   the number of hours to add.
     * @param minutes the number of minutes to add.
     * @param seconds the number of seconds to add.
     * @param millis  the number of milliseconds to add.
     * @return the updated Calendar instance.
     */
    // CSOFF: ParameterNumber
    public static Calendar add2Calendar(Calendar cal, int years, int months, int days, int hours, int minutes,
            int seconds, int millis)
    // CSON: ParameterNumber
    {
        if (years != 0)
            cal.add(Calendar.YEAR, years);

        if (months != 0)
            cal.add(Calendar.MONTH, months);

        if (days != 0)
            cal.add(Calendar.DAY_OF_MONTH, days);

        if (hours != 0)
            cal.add(Calendar.HOUR_OF_DAY, hours);

        if (minutes != 0)
            cal.add(Calendar.MINUTE, minutes);

        if (seconds != 0)
            cal.add(Calendar.SECOND, seconds);

        if (millis != 0)
            cal.add(Calendar.MILLISECOND, millis);

        return cal;
    }
}

Related

  1. add(Calendar calendar, int calendarField, int amount)
  2. add(Date _date, int _calendarField, int _amount)
  3. add(Date date, int calendarField, int amount)
  4. add(Date inputDate, int interval, int calendarUnit)
  5. add(final Date date, final int calendarField, final int amount)
  6. addCalendarDate(Calendar cal, int date)
  7. addCalendarMonthsToUnixtime(long time, int interval)
  8. addCalendarQuarterOfYear(Calendar cal, int quartersOfYear)
  9. addDate(Calendar baseDate, int addDate)