Here you can find the source of formatTime(long time)
Parameter | Description |
---|---|
time | a parameter |
public static String formatTime(long time)
//package com.java2s; //License from project: LGPL public class Main { /**/* w ww.j a va 2 s . c o m*/ * Format a milisecond number. * * @param time * @return String */ public static String formatTime(long time) { String elapsedTime; long seconds = time / 1000; long minutes = seconds / 60; long hours = minutes / 60; long sec_remainder = seconds % 60; long min_remainder = minutes % 60; long hours_remainder = hours % 24; if (minutes < 1) { elapsedTime = (seconds <= 9 ? "0" : "") + new Long(seconds).toString() + " sec"; } else { if (hours < 1) { elapsedTime = (minutes <= 9 ? "0" : "") + new Long(minutes).toString() + ":" + (sec_remainder <= 9 ? "0" : "") + new Long(sec_remainder).toString() + " min"; } else { elapsedTime = (hours <= 9 ? "0" : "") + new Long(hours).toString() + ":" + (min_remainder <= 9 ? "0" : "") + new Long(min_remainder).toString() + ":" + (sec_remainder <= 9 ? "0" : "") + new Long(sec_remainder).toString(); } } return elapsedTime; } }