Java Utililty Methods TimeUnit Usage

List of utility methods to do TimeUnit Usage

Description

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

Method

intsecondsToMillis(int seconds)
Converts given seconds to milliseconds.
return (int) TimeUnit.SECONDS.toMillis(seconds);
StringsecondsToYearsDaysHoursMinutesSeconds(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;
...
TimeUnitselectDurationUnitForDisplay(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;
...
voidsleep()
sleep
sleep(10);
voidsleep(int millis)
sleep
try {
    TimeUnit.MILLISECONDS.sleep(millis);
} catch (InterruptedException e) {
voidsleep(long durationMillis)
sleep
try {
    Thread.sleep(durationMillis);
} catch (InterruptedException e) {
    Thread.currentThread().interrupt();
voidsleep(long millis)
sleep
sleep(millis, TimeUnit.MILLISECONDS);
voidsleep(long milliseconds)
sleep
try {
    TimeUnit.MILLISECONDS.sleep(milliseconds);
} catch (InterruptedException e) {
    e.printStackTrace();
    Thread.currentThread().interrupt();
voidsleepForSeconds(int seconds)
sleep For Seconds
try {
    Thread.sleep(TimeUnit.SECONDS.toMillis(seconds));
} catch (InterruptedException ignored) {
voidsleepMilliseconds(long milliseconds)
Sleep in the unit of milliseconds.
try {
    TimeUnit.MILLISECONDS.sleep(milliseconds);
} catch (InterruptedException e) {