Here you can find the source of printTime(long time, TimeUnit unit)
public static String printTime(long time, TimeUnit unit)
//package com.java2s; //License from project: LGPL import java.util.concurrent.*; public class Main { public static String printTime(long time, TimeUnit unit) { long ns = TimeUnit.NANOSECONDS.convert(time, unit); long us = TimeUnit.MICROSECONDS.convert(time, unit); long ms = TimeUnit.MILLISECONDS.convert(time, unit); long secs = TimeUnit.SECONDS.convert(time, unit); if (secs > 0) return secs + "s"; if (ms > 0) return ms + "ms"; if (us > 0) return us + " us"; return ns + "ns"; }/*from w w w.j a va 2 s .co m*/ }