Here you can find the source of getUnit(long nanos)
public static TimeUnit getUnit(long nanos)
//package com.java2s; //License from project: Open Source License import java.util.concurrent.TimeUnit; public class Main { public static TimeUnit getUnit(long nanos) { for (TimeUnit unit : TimeUnit.values()) { long current = unit.convert(nanos, TimeUnit.NANOSECONDS); if (current < 1000) { return unit; }/*from w ww.jav a2 s . c o m*/ } return TimeUnit.NANOSECONDS; } }