Java Time Format formatNanosec(long timeNanosec)

Here you can find the source of formatNanosec(long timeNanosec)

Description

format Nanosec

License

Apache License

Declaration

public static String formatNanosec(long timeNanosec) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static final double MILLISEC_IN_NANOSEC = 1000 * 1000;
    public static final double SEC_IN_NANOSEC = MILLISEC_IN_NANOSEC * 1000;
    public static final double MIN_IN_NANOSEC = SEC_IN_NANOSEC * 60;
    public static final double HOUR_IN_NANOSEC = MIN_IN_NANOSEC * 60;
    public static final double DAY_IN_NANOSEC = HOUR_IN_NANOSEC * 24;

    public static String formatNanosec(long timeNanosec) {
        if (timeNanosec < 10 * SEC_IN_NANOSEC)
            return String.format("%10.2f", timeNanosec / MILLISEC_IN_NANOSEC) + " msec";
        if (timeNanosec < 10 * MIN_IN_NANOSEC)
            return String.format("%10.2f", timeNanosec / SEC_IN_NANOSEC) + " sec";
        if (timeNanosec < 10 * HOUR_IN_NANOSEC)
            return String.format("%10.2f", timeNanosec / MIN_IN_NANOSEC) + " min";
        if (timeNanosec < 10 * DAY_IN_NANOSEC)
            return String.format("%10.2f", timeNanosec / HOUR_IN_NANOSEC) + " hour";
        return String.format("%10.2f", timeNanosec / DAY_IN_NANOSEC) + " days";
    }//from  ww w .  j a  v a2  s  . c om
}

Related

  1. formatMeasures(final int quartersPerMeasure, final double time, final int startOffset)
  2. formatMicroSpan(long time)
  3. formatMili(long timeDelta)
  4. formatMs(long elapsedTime)
  5. formatMusicTime(int time)
  6. formatPeroid(long time)
  7. formatRemainingTime(float seccounds)
  8. formatRuntime(long runtime)
  9. formatRuntime(long time, boolean fixedlength)