Java Time Readable Format toTime(long nanos)

Here you can find the source of toTime(long nanos)

Description

to Time

License

Open Source License

Declaration

public static String toTime(long nanos) 

Method Source Code

//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();
    }
}

Related

  1. humanTime(long seconds)
  2. humanTime(long start, long end)
  3. toHumanable(long time_millsecod)
  4. toTime(int duration)
  5. toTime(long ms)
  6. toTime(long time)
  7. toTime2(int value, int nanos, int meta)
  8. toTimeExpression(long ms, int frames)
  9. toTimeFormat(String _srcTime)