Java Minute Format formatMinutes(long time, String timerPrecisionId, boolean round)

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

Description

format Minutes

License

Open Source License

Declaration

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

Method Source Code

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

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

        if (time == Long.MAX_VALUE) {
            return "DNF";
        }/*from www .j a v a  2  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 minutes = time / 6000;
            long seconds = (time / 100) % 60;
            long centiseconds = time % 100;
            result = sign
                    + (minutes < 10 ? "0" + minutes : minutes)
                    + ":"
                    + (seconds < 10 ? "0" + seconds : seconds)
                    + "."
                    + (centiseconds < 10 ? "0" + centiseconds
                            : centiseconds);
        } else if (timerPrecisionId.equals("MILLISECONDS")) {
            long minutes = time / 60000;
            long seconds = (time / 1000) % 60;
            long milliseconds = time % 1000;

            result = sign
                    + (minutes < 10 ? "0" + minutes : minutes)
                    + ":"
                    + (seconds < 10 ? "0" + seconds : seconds)
                    + "."
                    + (milliseconds < 10 ? "00" + milliseconds
                            : (milliseconds < 100 ? "0" + milliseconds
                                    : milliseconds));
        }

        return result;
    }
}

Related

  1. correctMinuteFormat(String minute)
  2. formatMinutes(double value)
  3. formatMinutes(int minutes)
  4. formatMinutes(long time)
  5. formatMinutes(long time)
  6. formatMinutes(long timeMinutes)
  7. formatSecondsToMinutes(int secontsTotal)
  8. formatTimeInMinutes(long l)
  9. getFormattedHoursAndMinutes(final long millis)