Here you can find the source of format(long elapsed, boolean hours)
private static String format(long elapsed, boolean hours)
//package com.java2s; //License from project: Open Source License import java.util.concurrent.TimeUnit; public class Main { private static String format(long elapsed, boolean hours) { final long hr = TimeUnit.MILLISECONDS.toHours(elapsed); final long min = TimeUnit.MILLISECONDS.toMinutes(elapsed - TimeUnit.HOURS.toMillis(hr)); final long sec = TimeUnit.MILLISECONDS .toSeconds(elapsed - TimeUnit.HOURS.toMillis(hr) - TimeUnit.MINUTES.toMillis(min)); return hours ? String.format("%02d:%02d:%02d", hr, min, sec) : String.format("%02d:%02d", min, sec); }// www . j av a 2 s . com }