Java Minute Get getHourMinuteSecond(long misSecond)

Here you can find the source of getHourMinuteSecond(long misSecond)

Description

get Hour Minute Second

License

Open Source License

Declaration

public static String getHourMinuteSecond(long misSecond) 

Method Source Code

//package com.java2s;

public class Main {
    public static String getHourMinuteSecond(long misSecond) {
        if (misSecond < 0) {
            throw new IllegalArgumentException("The misSecond must not be negative");
        }/*w  ww . jav a  2 s .  c  om*/

        long second = misSecond / 1000;
        long hour = second / 3600;
        long minute = (second % 3600) / 60;
        long sec = second % 3600 % 60;

        String hourStr = String.valueOf(hour);
        String minuteStr = String.valueOf(minute);
        String secStr = String.valueOf(sec);

        hourStr = extendTimeZeroChars(hourStr, 2);
        minuteStr = extendTimeZeroChars(minuteStr, 2);
        secStr = extendTimeZeroChars(secStr, 2);

        return hourStr + ":" + minuteStr + ":" + secStr;
    }

    private static String extendTimeZeroChars(String str, int len) {
        String s = str;
        if (str.length() >= len) {
            return str;
        } else {
            for (int i = 0; i < (len - str.length()); i++) {
                s = "0" + s;
            }
            return s;
        }
    }
}

Related

  1. getCompleteDayAsHourMinuteString()
  2. getElapsedTimeHoursMinutesFromMilliseconds(long milliseconds)
  3. getFiveMinuteCronByHostId(long hostId)
  4. getFrequencyValueInMinutes(long value)
  5. getHMTimeInMinutes(final String timeStr)
  6. getHoursMinutesSeconds(float timeInSeconds)
  7. getLessThanOneMinuteAgoRendering()
  8. getMilliSecondFromMinute(int minute)
  9. getMin()