Here you can find the source of formatNanoseconds (final long ns)
public static String formatNanoseconds (final long ns)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file public class Main { public static String formatNanoseconds(final long ns) { String s;// w ww.j av a 2s . c o m final long NS_ONE_MICROSECOND = 1_000L; final long NS_ONE_MILLISECOND = 1_000L * NS_ONE_MICROSECOND; final long NS_ONE_SECOND = 1_000 * NS_ONE_MILLISECOND; final long NS_ONE_MINUTE = 60L * NS_ONE_SECOND; final long NS_ONE_HOUR = 60L * NS_ONE_MINUTE; final long NS_ONE_DAY = 24L * NS_ONE_HOUR; if (ns < NS_ONE_MICROSECOND) { s = String.format("%dns", ns); } else if (ns < NS_ONE_MILLISECOND) { s = String.format("%dus", ns / NS_ONE_MICROSECOND); } else if (ns < NS_ONE_SECOND) { s = String.format("%dms", ns / NS_ONE_MILLISECOND); } else if (ns < NS_ONE_MINUTE) { s = String .format("%.1fs", (double) ns / (double) NS_ONE_SECOND); } else if (ns < NS_ONE_HOUR) { s = String .format("%.1fm", (double) ns / (double) NS_ONE_MINUTE); } else if (ns < NS_ONE_DAY) { s = String.format("%.1fh", (double) ns / (double) NS_ONE_HOUR); } else { s = String.format("%.1fd", (double) ns / (double) NS_ONE_DAY); } return s; } }