Here you can find the source of formatTime(long time)
Parameter | Description |
---|---|
time | to format in seconds |
public static String formatTime(long time)
//package com.java2s; // it under the terms of the GNU General Public License as published by public class Main { /** Formats time string from seconds. *//from ww w.j a va 2s.c o m * @param time to format in seconds * @return time formatted as hh:mm:ss */ public static String formatTime(long time) { StringBuffer result = new StringBuffer(); // determine hours and minutes from seconds long hour = time / 3600; time -= (hour * 3600); long min = time / 60; time -= (min * 60); long sec = time; // format to string // append hour if (hour > 0) { result.append(hour).append(":"); if (min < 10) { result.append("0"); } } // append min result.append(min).append(":"); // append sec if (sec < 10) { result.append("0"); } result.append(sec); return result.toString(); } }