Here you can find the source of millisecondsToTimeString(int milliseconds)
public static String millisecondsToTimeString(int milliseconds)
//package com.java2s; /*//w w w . j a va 2 s . c o m * Copyright 2013 Elina Vartiainen and Simon Robinson * * This file is part of Com-Me. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { public static String millisecondsToTimeString(int milliseconds) { // overestimating is better than just rounding double secondsDouble = (milliseconds / 1000d); int secondsIn = (int) ((secondsDouble - (int) secondsDouble) > 0 ? secondsDouble + 1 : secondsDouble); int hours = secondsIn / 3600; int remainder = secondsIn % 3600; int minutes = remainder / 60; int seconds = remainder % 60; return (hours > 0 ? hours + ":" : "") + (hours > 0 && minutes < 10 ? "0" : "") + minutes + ":" + (seconds < 10 ? "0" : "") + seconds; } }