Java Time Format formatTime(long millis)

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

Description

format Time

License

Open Source License

Declaration

public static String formatTime(long millis) 

Method Source Code

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

public class Main {
    public static String formatTime(long millis) {
        if (millis == Long.MAX_VALUE) {
            return "LIVE";
        }/*www .j  a  v  a 2 s .  c  o m*/

        long t = millis / 1000L;
        int sec = (int) (t % 60L);
        int min = (int) ((t % 3600L) / 60L);
        int hrs = (int) (t / 3600L);

        String timestamp;

        if (hrs != 0) {
            timestamp = forceTwoDigits(hrs) + ":" + forceTwoDigits(min)
                    + ":" + forceTwoDigits(sec);
        } else {
            timestamp = forceTwoDigits(min) + ":" + forceTwoDigits(sec);
        }

        return timestamp;
    }

    private static String forceTwoDigits(int i) {
        return i < 10 ? "0" + i : Integer.toString(i);
    }
}

Related

  1. formatTime(Integer hour, Integer minute, Integer second, Integer ampm, Integer zoneOffset)
  2. formatTime(Integer seconds)
  3. formatTime(long dtNanos)
  4. formatTime(long elapsedTime)
  5. formatTime(long elapsedTime)
  6. formatTime(long millis)
  7. formatTime(long millis)
  8. formatTime(long millis)
  9. formatTime(long millis, int precision)