Here you can find the source of formatNanosec(long timeNanosec)
public static String formatNanosec(long timeNanosec)
//package com.java2s; //License from project: Apache License public class Main { public static final double MILLISEC_IN_NANOSEC = 1000 * 1000; public static final double SEC_IN_NANOSEC = MILLISEC_IN_NANOSEC * 1000; public static final double MIN_IN_NANOSEC = SEC_IN_NANOSEC * 60; public static final double HOUR_IN_NANOSEC = MIN_IN_NANOSEC * 60; public static final double DAY_IN_NANOSEC = HOUR_IN_NANOSEC * 24; public static String formatNanosec(long timeNanosec) { if (timeNanosec < 10 * SEC_IN_NANOSEC) return String.format("%10.2f", timeNanosec / MILLISEC_IN_NANOSEC) + " msec"; if (timeNanosec < 10 * MIN_IN_NANOSEC) return String.format("%10.2f", timeNanosec / SEC_IN_NANOSEC) + " sec"; if (timeNanosec < 10 * HOUR_IN_NANOSEC) return String.format("%10.2f", timeNanosec / MIN_IN_NANOSEC) + " min"; if (timeNanosec < 10 * DAY_IN_NANOSEC) return String.format("%10.2f", timeNanosec / HOUR_IN_NANOSEC) + " hour"; return String.format("%10.2f", timeNanosec / DAY_IN_NANOSEC) + " days"; }//from ww w . j a v a2 s . c om }