Java Second Add addSeconds(final Date date, final int seconds)

Here you can find the source of addSeconds(final Date date, final int seconds)

Description

add Seconds

License

Open Source License

Declaration

public static Date addSeconds(final Date date, final int seconds) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static final long HOUR = 60 * 60 * 1000;
    public static final long MINUTE = 60 * 1000;
    public static final long SECOND = 1000L;

    public static Date addSeconds(final Date date, final int seconds) {
        final Calendar c = Calendar.getInstance();
        c.setTime(date);// w w w  .j  av a 2s  . com
        c.add(Calendar.SECOND, seconds);
        final Date end = c.getTime();
        return end;
    }

    public static String getTime(final long time) {
        if (time <= 0) {
            return "";
        }
        if (time < SECOND) {
            return time + "ms";
        } else if (time < MINUTE) {
            return (time / SECOND) + "s" + getTime(time % SECOND);
        } else if (time < HOUR) {
            return (time / MINUTE) + "m" + getTime(time % MINUTE);
        } else if (time >= HOUR) {
            return (time / HOUR) + "h" + getTime(time % HOUR);
        }
        return "";
    }
}

Related

  1. addSecond(Date date, int second)
  2. addSecond(Date source, int s)
  3. addSecond(int second)
  4. addSeconds(Date date, int seconds)
  5. addSeconds(Date date, int seconds)
  6. addSeconds(int addSeconds)