Here you can find the source of selectDurationUnitForDisplay(long durationInNanos)
static TimeUnit selectDurationUnitForDisplay(long durationInNanos)
//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; } } }