Here you can find the source of formatMillis(long millis)
public static String formatMillis(long millis)
//package com.java2s; /* 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./*from www.j a v a2s. c o m*/ */ public class Main { /** * Returns a formatted string using the pattern hh:mm:ss. The hours are * omitted if they are zero, the minutes are padded with a '0' character * if they are less than 10. */ public static String formatMillis(long millis) { int hours = (int) (millis / (1000 * 60 * 60)); int minutes = (int) (millis / (1000 * 60)) % 60; int seconds = (int) (millis / 1000) % 60; StringBuilder sb = new StringBuilder(); if (hours > 0) { sb.append(hours); sb.append(':'); } if (minutes < 10 && hours > 0) { sb.append(0); } sb.append(minutes); sb.append(':'); if (seconds < 10) { sb.append(0); } sb.append(seconds); return sb.toString(); } }