Creates a calendar that represents the date offset seconds from now. - Java java.util

Java examples for java.util:Second

Description

Creates a calendar that represents the date offset seconds from now.

Demo Code


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

public class Main {
    public static void main(String[] argv) throws Exception {
        int offset = 2;
        System.out.println(createCalendar(offset));
    }/*from   ww  w  .ja v  a 2  s .  c  o m*/

    /**
     * Creates a calendar that represents the date offset seconds from now.
     * 
     * @param offset
     *            offset in seconds
     * @return the new calendar
     */
    public static Calendar createCalendar(int offset) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.SECOND, offset);
        return calendar;
    }
}

Related Tutorials