Java Millisecond Convert MillisToTimeString(long millis)

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

Description

Millis To Time String

License

Apache License

Declaration

public static String MillisToTimeString(long millis) 

Method Source Code

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

public class Main {
    public static String MillisToTimeString(long millis) {
        int hours, minutes, seconds;
        float timeValue = millis / 3600000.0f;
        hours = (int) Math.floor(timeValue);
        minutes = (int) Math.floor((timeValue - hours) * 60);
        seconds = (int) Math.round((timeValue - hours - (minutes / 60.0f)) * 3600);
        if (seconds >= 60) {
            seconds -= 60;/*from   ww  w  . j  av a 2 s.c o m*/
            minutes += 1;
        }
        if (minutes >= 60) {
            minutes -= 60;
            hours += 1;
        }

        String formattedFreq = "";
        if (hours != 0) {
            formattedFreq = String.valueOf(hours) + ":";
        }
        formattedFreq += String.format("%02d:%02d", minutes, seconds);

        return formattedFreq;
    }
}

Related

  1. millisToTime(final long time)
  2. millisToTime(float millis)
  3. millisToTime(long ms)
  4. millisToTimeSpan(final long interv)
  5. millisToTimeSpan(long millis)
  6. millisToWords(long millis)
  7. toMillis(int seconds)
  8. toMillis(int timeInSecs)
  9. toMillis(long nanos)