Android Milliseconds to Minutes And Seconds Convert milisecondsToMinutesAndSeconds(int milliseconds)

Here you can find the source of milisecondsToMinutesAndSeconds(int milliseconds)

Description

miliseconds To Minutes And Seconds

Declaration

public static String milisecondsToMinutesAndSeconds(int milliseconds) 

Method Source Code

//package com.java2s;

public class Main {
    public static String milisecondsToMinutesAndSeconds(int milliseconds) {
        int seconds = (int) (milliseconds / 1000) % 60;
        int minutes = (int) ((milliseconds / (1000 * 60)) % 60);
        int hours = (int) ((milliseconds / (1000 * 60 * 60)) % 24);

        StringBuffer buffer = new StringBuffer();
        String prefix = "";
        if (hours > 0) {
            prefix = hours < 10 ? "0" : "";
            buffer.append(prefix + hours + ":");
        }/*from  ww w  .  j  a v a2  s  .  c o m*/

        prefix = minutes < 10 ? "0" : "";
        buffer.append(prefix + minutes + ":");

        prefix = seconds < 10 ? "0" : "";
        buffer.append(prefix + seconds);

        return buffer.toString();
    }
}

Related

  1. getMinute(long dateTimeMillis)
  2. getMillisecondsUntilNextMinute()