Java Millisecond Convert millisToHMSShort(long millis)

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

Description

millis To HMS Short

License

Apache License

Declaration

public static String millisToHMSShort(long millis) 

Method Source Code

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

public class Main {
    private static final String SHORT_FORMAT = millisToHMS(0);

    public static String millisToHMSShort(long millis) {
        boolean minus = false;
        if (millis < 0) {
            minus = true;/*  ww w.j a v a 2 s .com*/
            millis = -millis;
        }
        String hms = millisToHMS(millis);
        int i;
        for (i = 0; i < hms.length() - 1; i++) {
            if (hms.charAt(i) != SHORT_FORMAT.charAt(i)) {
                break;
            }
        }
        String hmsShort = hms.substring(i);
        return minus ? "-" + hmsShort : hmsShort;
    }

    public static String millisToHMS(long millis) {
        boolean minus = false;
        if (millis < 0) {
            minus = true;
            millis = -millis;
        }
        long s = millis / 1000;
        long m = s / 60;
        long h = m / 60;
        String hms = String.format("%02d:%02d:%02d", h, m % 60, s % 60);
        return minus ? "-" + hms : hms;
    }
}

Related

  1. millisToDateString(Long Millis)
  2. millisToDays(long millis)
  3. millisToDuration(long millis)
  4. millisToDurationString(long millis)
  5. millisToHMS(long millis)
  6. millisToLongDHMS(long duration)
  7. millisToLongDHMS(long duration)
  8. millisToLongDHMS(long duration, String pubDate)
  9. millisToLongM(long duration)