Java Time Elapsed elapsed(long duration, long required)

Here you can find the source of elapsed(long duration, long required)

Description

Checks whether a certain amount of milliseconds have elapsed a given time in milliseconds.

License

Open Source License

Parameter

Parameter Description
duration the real time milliseconds.
required the amount of milliseconds that is required to have passed the duration in order to succeed

Return

whether the required milliseconds have elapsed the duration

Declaration

public static boolean elapsed(long duration, long required) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**// w w  w  . ja  v  a2 s . co m
     * Checks whether a certain amount of milliseconds have elapsed a given time in  milliseconds.
     * This method simply subtracts the given duration from the current time in milliseconds and
     * checks if the result is greater than the required amount of milliseconds.
     * <pre>
     *   TimeUtils.elapsed(now - 1000, 1000) = true
     *   TimeUtils.elapsed(now - 999, 1000) = true
     *   TimeUtils.elapsed(now, 1000) = false
     * </pre>
     *
     * @param duration the real time milliseconds.
     * @param required the amount of milliseconds that is required to have passed the {@code
     * duration} in order to succeed
     *
     * @return whether the {@code required} milliseconds have elapsed the {@code duration}
     */
    public static boolean elapsed(long duration, long required) {
        return System.currentTimeMillis() - duration >= required;
    }
}

Related

  1. elapsed(long from, long required)
  2. elapsed(long from, long to)
  3. elapsedMicros(String startTime, String endTime)
  4. elapsedNanos(long nanoseconds)