static String durationInDurationUnitsAsStr(long nanos, DurationUnit durationUnit) {
        StringBuilder buf = new StringBuilder();
        switch (durationUnit) {
        case NANOSECOND:
            buf.append(nanos);
            break;
        case MICROSECOND:
            double micros = convertToMicros(nanos);
            buf.append(DECIMAL_FORMAT.format(micros));
            break;
        case MILLISSECOND:
            double millis = convertToMillis(nanos);
            buf.append(DECIMAL_FORMAT.format(millis));
            break;
        case SECOND:
            double seconds = convertToSeconds(nanos);
            buf.append(DECIMAL_FORMAT.format(seconds));
            break;
        }
        return buf.toString();
    }
A collection of utility methods.

@author Ceki G&uuml;lc&uuml;
slf4j-ext/src/main/java/org/slf4j/profiler/Util.java