Java TimeUnit Usage selectDurationUnitForDisplay(long durationInNanos)

Here you can find the source of selectDurationUnitForDisplay(long durationInNanos)

Description

select Duration Unit For Display

License

Open Source License

Declaration

static TimeUnit selectDurationUnitForDisplay(long durationInNanos) 

Method Source Code

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

import java.util.concurrent.TimeUnit;

public class Main {
    static final long NANOS_IN_ONE_MICROSECOND = 1000;
    static final long NANOS_IN_ONE_MILLISECOND = NANOS_IN_ONE_MICROSECOND * 1000;
    static final long NANOS_IN_ONE_SECOND = NANOS_IN_ONE_MILLISECOND * 1000;

    static TimeUnit selectDurationUnitForDisplay(long durationInNanos) {
        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 {//from  www.  j av a  2  s  .  c  om
            return TimeUnit.SECONDS;
        }
    }
}

Related

  1. secondsPassed(int startTime)
  2. secondsToETA(long secondsTotal)
  3. secondsToHMS(long seconds)
  4. secondsToMillis(int seconds)
  5. secondsToYearsDaysHoursMinutesSeconds(double seconds)
  6. sleep()
  7. sleep(int millis)
  8. sleep(long durationMillis)
  9. sleep(long millis)