Pages

Saturday 21 January 2012

MilliSecond to HH:MM:SS format convertor

All thanks to Stack overflow post complete function to get HH:MM:SS format for given time in millisecond.




private String formatTime(long millis) {
            String output = "00:00:00";
            long seconds = millis / 1000;
            long minutes = seconds / 60;
            long hours = minutes / 60;
 
            seconds = seconds % 60;
            minutes = minutes % 60;
            hours = hours % 60;
 
            String secondsD = String.valueOf(seconds);
            String minutesD = String.valueOf(minutes);
            String hoursD = String.valueOf(hours);
 
            if (seconds < 10)
                  secondsD = "0" + seconds;
            if (minutes < 10)
                  minutesD = "0" + minutes;
            if (hours < 10)
                  hoursD = "0" + hours;
 
            output = hoursD + " : " + minutesD + " : " + secondsD;
            return output;
      }

1 comment:

  1. Casinos in Malta - Filmfile Europe
    Find the best Casinos in Malta including bonuses, games, games and the history of herzamanindir.com/ games. We 토토 사이트 cover all https://septcasino.com/review/merit-casino/ the 바카라사이트 main 출장마사지 reasons to visit Casinos in

    ReplyDelete