Java Utililty Methods Time Elapsed

List of utility methods to do Time Elapsed

Description

The list of methods to do Time Elapsed are organized into topic(s).

Method

booleanelapsed(long duration, long required)
Checks whether a certain amount of milliseconds have elapsed a given time in milliseconds.
return System.currentTimeMillis() - duration >= required;
booleanelapsed(long from, long required)
Check if enough time has passed by from a certain moment.
return System.currentTimeMillis() - from > required;
booleanelapsed(long from, long to)
elapsed
return System.currentTimeMillis() - from >= to;
longelapsedMicros(String startTime, String endTime)
Gets elapsed millis from the times on the timeline
return (long) ((new Double(endTime) - new Double(startTime)) * 1000);
StringelapsedNanos(long nanoseconds)
Returns a string representation of the specified elapsed time in the format "H hours M minutes S seconds".
long seconds = Math.round(nanoseconds / 1000000000.0);
StringBuilder sb = new StringBuilder(80);
if (seconds >= 3600) {
    long hours = seconds / 3600;
    sb.append(hours);
    sb.append(hours == 1 ? " hour " : " hours ");
    seconds %= 3600;
if (seconds >= 60) {
    long minutes = seconds / 60;
    sb.append(minutes);
    sb.append(minutes == 1 ? " minute " : " minutes ");
    seconds %= 60;
sb.append(seconds);
sb.append(seconds == 1 ? " second" : " seconds");
return sb.toString();
longelapsedNanos(long startNanoTime)
Nanoseconds elapsed since the time specified, the input is nanoTime the only conversion happens when computing the elapsed time.
return System.nanoTime() - startNanoTime;
longelapsedTime(long endTime, long beginTime)
elapsed Time
return endTime - beginTime;
StringelapsedTime(long milli)
Formats a time interval in milliseconds to a String in the form "hours:minutes:seconds:millis"
long seconds = milli / 1000;
milli %= 1000;
long minutes = seconds / 60;
seconds %= 60;
long hours = minutes / 60;
minutes %= 60;
return hours + "h " + minutes + "m " + seconds + "s " + milli;
StringelapsedTime(long ms)
elapsed Time
String unit = "ms";
long value = ms;
long rem = 0;
if (ms >= 3600000) {
    unit = "h";
    value = ms / 3600000;
    rem = ms % 3600000;
} else if (ms >= 60000) {
...
doubleelapsedTime(long startTime, long endTime, double units)
elapsed Time
return (endTime - startTime) / units;