Java Date Difference nextSeconds(Date date, int diff)

Here you can find the source of nextSeconds(Date date, int diff)

Description

next Seconds

License

Apache License

Declaration

public static Date nextSeconds(Date date, int diff) 

Method Source Code

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

import java.util.*;

public class Main {
    public static final long SECOND = 1000;

    public static Date nextSeconds(int diff) {
        return add(new Date(), Calendar.SECOND, diff);
    }/*from  ww w  .j ava 2s . c om*/

    public static Date nextSeconds(Date date, int diff) {
        return add(date, Calendar.SECOND, diff);
    }

    /**
     * @since 2008-01-02
     */
    public static Date add(Date date, int field, int diff) {
        Calendar c = getCalendar(date);
        c.add(field, diff);
        return c.getTime();
    }

    /**
     * @since 2008-01-02
     */
    public static Date add(int field, int diff) {
        return add(new Date(), field, diff);
    }

    /**
     * @since 2008-01-02
     */
    public static Calendar getCalendar(long millis) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(millis);
        return c;
    }

    /**
     * @since 2008-01-02
     */
    public static Calendar getCalendar(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c;
    }
}

Related

  1. getDiffMon(Date dt, int idiff)
  2. getDiffToString(Date date, int n, String pattern)
  3. getScoreDifferenceString(int newNumber, int oldNumber)
  4. getSecondDiff(Date d1, Date d2)
  5. getTimeDifferenceInSeconds(Date d, Date d2)
  6. parseParamDate(final String diff)
  7. timeDiff(Calendar date1, Calendar date2)
  8. timeDiffHourMinSec(Date start, Date end)