List of utility methods to do TimeUnit Usage
int | secondsToMillis(int seconds) Converts given seconds to milliseconds. return (int) TimeUnit.SECONDS.toMillis(seconds); |
String | secondsToYearsDaysHoursMinutesSeconds(double seconds) Converts a timestamp in seconds into its equivalent representation in days, hours, minutes and seconds. if (seconds == Double.MAX_VALUE) return "infinity"; long aux_seconds = (long) seconds; long days = TimeUnit.SECONDS.toDays(aux_seconds); long months = (long) Math.floor((double) days / 30); long years = (long) Math.floor((double) months / 12); months %= 12; days %= 30; ... |
TimeUnit | selectDurationUnitForDisplay(long durationInNanos) select Duration Unit For Display if (durationInNanos < 10 * NANOS_IN_ONE_MICROSECOND) { return TimeUnit.NANOSECONDS; } else if (durationInNanos < 10 * NANOS_IN_ONE_MILLISECOND) { return TimeUnit.MICROSECONDS; } else if (durationInNanos < 10 * NANOS_IN_ONE_SECOND) { return TimeUnit.MILLISECONDS; } else { return TimeUnit.SECONDS; ... |
void | sleep() sleep sleep(10); |
void | sleep(int millis) sleep try { TimeUnit.MILLISECONDS.sleep(millis); } catch (InterruptedException e) { |
void | sleep(long durationMillis) sleep try { Thread.sleep(durationMillis); } catch (InterruptedException e) { Thread.currentThread().interrupt(); |
void | sleep(long millis) sleep sleep(millis, TimeUnit.MILLISECONDS); |
void | sleep(long milliseconds) sleep try { TimeUnit.MILLISECONDS.sleep(milliseconds); } catch (InterruptedException e) { e.printStackTrace(); Thread.currentThread().interrupt(); |
void | sleepForSeconds(int seconds) sleep For Seconds try { Thread.sleep(TimeUnit.SECONDS.toMillis(seconds)); } catch (InterruptedException ignored) { |
void | sleepMilliseconds(long milliseconds) Sleep in the unit of milliseconds. try { TimeUnit.MILLISECONDS.sleep(milliseconds); } catch (InterruptedException e) { |