Java Second Format formatSeconds(long time, String timerPrecisionId, boolean round)

Here you can find the source of formatSeconds(long time, String timerPrecisionId, boolean round)

Description

format Seconds

License

Open Source License

Declaration

public static String formatSeconds(long time, String timerPrecisionId,
            boolean round) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String formatSeconds(long time, String timerPrecisionId,
            boolean round) {
        String result = "";

        if (time == Long.MAX_VALUE) {
            return "DNF";
        }//from   ww w.j av a2  s  . c  o  m

        String sign = "";
        if (time < 0) {
            sign = "-";
            time = -time;
        }

        if (timerPrecisionId.equals("CENTISECONDS")) {
            if (round) {
                time = time + 5;
            }
            time = time / 10;

            long seconds = time / 100;
            long centiseconds = time % 100;
            result = sign
                    + seconds
                    + "."
                    + (centiseconds < 10 ? "0" + centiseconds
                            : centiseconds);
        } else if (timerPrecisionId.equals("MILLISECONDS")) {
            long seconds = time / 1000;
            long milliseconds = time % 1000;
            result = sign
                    + seconds
                    + "."
                    + (milliseconds < 10 ? "00" + milliseconds
                            : (milliseconds < 100 ? "0" + milliseconds
                                    : milliseconds));
        }

        return result;
    }
}

Related

  1. formatSeconds(long seconds)
  2. formatSeconds(long seconds)
  3. formatSeconds(long secsIn)
  4. formatSeconds(long time)
  5. formatSeconds(long time)
  6. formatSecondsRegular(int seconds)
  7. formatSecondsWithHour(int seconds)
  8. formatTime(Date d, Locale locale, boolean withSeconds)
  9. formatTime(double seconds)