Add the given amount of seconds to the given calendar. - Java java.util

Java examples for java.util:Calendar Calculation

Description

Add the given amount of seconds to the given calendar.

Demo Code


//package com.java2s;
import java.util.Calendar;

public class Main {
    public static void main(String[] argv) throws Exception {
        Calendar calendar = Calendar.getInstance();
        int seconds = 2;
        addSeconds(calendar, seconds);/*ww w .  jav a  2  s.  co  m*/
    }

    /**
     * Add the given amount of seconds to the given calendar. The changes are
     * reflected in the given calendar.
     * 
     * @param calendar
     *            The calendar to add the given amount of seconds to.
     * @param seconds
     *            The amount of seconds to be added to the given calendar.
     *            Negative values are also allowed, it will just go back in
     *            time.
     */
    public static void addSeconds(Calendar calendar, int seconds) {
        calendar.add(Calendar.SECOND, seconds);
    }
}

Related Tutorials