Java Utililty Methods TimeUnit Calculate

List of utility methods to do TimeUnit Calculate

Description

The list of methods to do TimeUnit Calculate are organized into topic(s).

Method

booleansleepAndCachedInterruptedException(long sleepFor, TimeUnit unit)
Sleep and cached InterruptedException.
if (sleepFor <= 0) {
    return true;
try {
    unit.sleep(sleepFor);
    return true;
} catch (InterruptedException e) {
    return false;
...
voidsleepFor(long period, TimeUnit timeUnit)
This method is a convenience method for sleep that "swallows" InterruptedException and has TimeUnit parameter in addition to time period so it makes it very convenient.
try {
    timeUnit.sleep(period);
} catch (InterruptedException ie) {
longtimeDiff(Calendar end, Calendar begin, TimeUnit timeUnit)
time Diff
long timeDiff = 0L;
long diffMills = end.getTime().getTime() - begin.getTime().getTime();
switch (timeUnit) {
case DAYS:
    timeDiff = diffMills / (1000 * 60 * 60 * 24);
    break;
case HOURS:
    timeDiff = diffMills / (1000 * 60 * 60);
...
longtimeDiff(Date date1, Date date2, TimeUnit minutes)
time Diff
return minutes.convert(date1.getTime() - date2.getTime(), TimeUnit.MILLISECONDS);
longtimeSince(final long startNanos, final TimeUnit destUnit)
time Since
return destUnit.convert(System.nanoTime() - startNanos, TimeUnit.NANOSECONDS);
voidwaitForEnd(Process process, long timeout, TimeUnit unit)
The same as calling Process#waitFor(long,TimeUnit) .
process.waitFor(timeout, unit);