Here you can find the source of formatTime(long seconds)
public static String formatTime(long seconds)
//package com.java2s; //License from project: Open Source License public class Main { /** Format elapsed time as [[h+]:[mm]]:ss. */ public static String formatTime(long seconds) { StringBuilder buffer = new StringBuilder(8); if (seconds < 0) { buffer.append('-'); seconds *= -1;//from w w w . j a va 2 s.c o m } long hours = seconds / 3600; if (hours > 0) { if (hours > 9999) // Extremely large numbers are likely a problem in // Date.getTime(), as it can happen when running in the // netbeans profiler (version 5.5) return "--:--"; buffer.append(hours); buffer.append(':'); } seconds %= 3600; long minutes = seconds / 60; seconds %= 60; if (minutes >= 10) buffer.append(minutes); else { buffer.append('0'); buffer.append(minutes); } buffer.append(':'); if (seconds >= 10) buffer.append(seconds); else { buffer.append('0'); buffer.append(seconds); } return buffer.toString(); } }