Java Time Format formatTime(long time)

Here you can find the source of formatTime(long time)

Description

format Time

License

Open Source License

Declaration

public static String formatTime(long time) 

Method Source Code

//package com.java2s;

public class Main {
    public static final long SECONDS_IN_MILLIS = 1000L;
    public static final long MINUTE_IN_MILLIS = 60 * SECONDS_IN_MILLIS;
    public static final String SECONDS = " seconds";
    private static final String MILLIS = " ms";

    public static String formatTime(long time) {
        if (time > MINUTE_IN_MILLIS) {
            return formatMinutes(time);
        }/* w w  w.ja va 2  s.  co  m*/
        if (time > SECONDS_IN_MILLIS) {
            return formatSeconds(time);
        } else {
            return formatMillis(time);
        }
    }

    private static String formatMinutes(long time) {
        //todo - implement this method.
        return formatSeconds(time);
    }

    private static String formatSeconds(long time) {
        long kbsize = Math.round((float) time / SECONDS_IN_MILLIS); //format 0 decimal places
        return String.valueOf(kbsize) + SECONDS;
    }

    private static String formatMillis(long time) {
        return time + MILLIS;
    }
}

Related

  1. formatTime(long time)
  2. formatTime(long time)
  3. formatTime(long time)
  4. formatTime(long time)
  5. formatTime(long time)
  6. formatTime(long time)
  7. formatTime(long time)
  8. formatTime(long time)
  9. formatTime(long time, String syntax, boolean extraZeros)