Here you can find the source of toTime(long nanos)
public static String toTime(long nanos)
//package com.java2s; //License from project: Open Source License public class Main { public static String toTime(long nanos) { if (nanos < 1_000_000L) { return nanos + " ns"; }/*from w w w . j a v a 2 s . c o m*/ long l; StringBuilder builder = new StringBuilder(); if (nanos >= 60_000_000_000L) // minutes { l = nanos / 60_000_000_000L; builder.append(l).append(" min "); nanos -= l * 60_000_000_000L; } if (nanos >= 1_000_000_000L) // seconds { l = nanos / 1_000_000_000L; builder.append(l).append(" s "); nanos -= l * 1_000_000_000L; } if (nanos >= 1_000_000L) // milliseconds { l = nanos / 1_000_000L; builder.append(l).append(" ms "); // nanos -= l * 1_000_000L; } return builder.deleteCharAt(builder.length() - 1).toString(); } }