Java Second Calculate secondsLater(Integer seconds)

Here you can find the source of secondsLater(Integer seconds)

Description

Get date for number of seconds later

License

Apache License

Parameter

Parameter Description
seconds number of seconds

Return

date

Declaration

public static Date secondsLater(Integer seconds) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    /**/*from w  w  w  .j a  v a2  s. c  om*/
     * Get date for number of seconds later
     *
     * @param seconds number of seconds
     * @return date
     */
    public static Date secondsLater(Integer seconds) {
        return forCalendarDiff(Calendar.SECOND, seconds);
    }

    /**
     * Get date for calendar difference from current date
     *
     * @param field  difference field (Calendar.DATE, Calendar.MINUTE ... etc)
     * @param amount how much?
     * @return date for the difference
     */
    public static Date forCalendarDiff(int field, int amount) {
        GregorianCalendar gCal = new GregorianCalendar();
        gCal.add(field, amount);
        return new Date(gCal.getTimeInMillis());
    }
}

Related

  1. computeStartOfNextSecond(long now)
  2. getMillisecond(long num, int unit)
  3. getSecond(long t)
  4. getSecond(String s)
  5. nextSecond(int second)