public static String nanoTimeToString(long t) {
    if (t < 0) return "ERR";

    if (t == 0) return "0";

    if (t < 1000) {
      return t + "ns";
    }

    double us = (double) t / 1000;
    if (us < 1000) {
      return String.format("%.2fus", us);
    }

    double ms = us / 1000;
    if (ms < 1000) {
      return String.format("%.2fms", ms);
    }

    double ss = ms / 1000;
    if (ss < 1000) {
      return String.format("%.2fs", ss);
    }

    long mm = (long) ss / 60;
    ss -= mm * 60;
    long hh = mm / 60;
    mm -= hh * 60;
    long dd = hh / 24;
    hh -= dd * 24;

    if (dd > 0) {
      return String.format("%dd%dh", dd, hh);
    }

    if (hh > 0) {
      return String.format("%dh%dm", hh, mm);
    }

    if (mm > 0) {
      return String.format("%dm%.1fs", mm, ss);
    }

    return String.format("%.2fs", ss);

    /**
     * StringBuilder sb = new StringBuilder(); String sep = ""; if (dd > 0) { String unit = (dd > 1)
     * ? "days" : "day"; sb.append(String.format("%s%d%s", sep, dd, unit)); sep = " "; } if (hh > 0)
     * { String unit = (hh > 1) ? "hrs" : "hr"; sb.append(String.format("%s%d%s", sep, hh, unit));
     * sep = " "; } if (mm > 0) { String unit = (mm > 1) ? "mins" : "min";
     * sb.append(String.format("%s%d%s", sep, mm, unit)); sep = " "; } if (ss > 0) { String unit =
     * (ss > 1) ? "secs" : "sec"; sb.append(String.format("%s%.3f%s", sep, ss, unit)); sep = " "; }
     * return sb.toString();
     */
  }
A utility method to format a time duration in nano seconds into a human understandable stirng.
Time duration in nano seconds.
@return String representation.
hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/NanoTimer.java