Here you can find the source of formatDuration(long duration)
Parameter | Description |
---|---|
duration | a parameter |
public static String formatDuration(long duration)
//package com.java2s; //License from project: LGPL public class Main { /**/*from w w w. ja v a 2 s .c om*/ * Formats duration in miliseconds to hh:mm:ss string. Returns empty string * for duration lesser than zero. * * @param duration * @return Formatted duration. */ public static String formatDuration(long duration) { if (duration < 0) { return ""; } //to seconds duration /= 1000; short seconds = (short) (duration % 60); duration -= seconds; //to minutes duration /= 60; short minutes = (short) (duration % 60); duration -= minutes; short hours = (short) (duration / 60); return String.format("%d:%02d:%02d", hours, minutes, seconds); } }