Here you can find the source of formatTimeInMilliSeconds(long duration)
Parameter | Description |
---|---|
duration | a parameter |
public static String formatTimeInMilliSeconds(long duration)
//package com.java2s; import java.util.concurrent.TimeUnit; public class Main { /**/*from w w w. j av a 2s . co m*/ * Formats the time into mill * @param duration * @return */ public static String formatTimeInMilliSeconds(long duration) { try { StringBuffer durationInString = new StringBuffer(""); //TODO: add hours here as well long minutes = TimeUnit.MILLISECONDS.toSeconds(duration) / 60; long seconds = TimeUnit.MILLISECONDS.toSeconds(duration - minutes * 60 * 1000); long milliseconds = duration - (minutes * 60 * 1000) - seconds * 1000; if (minutes > 0) { durationInString.append(minutes).append(" min "); } if (seconds > 0) { durationInString.append(seconds).append(" sec "); } if (milliseconds > 0) { durationInString.append(milliseconds).append(" msec"); } return durationInString.toString(); } catch (Exception e) { e.printStackTrace(); return "-1"; } } }