Here you can find the source of formatDuration(long millis)
Parameter | Description |
---|---|
date | - created from milliseconds |
public static String formatDuration(long millis)
//package com.java2s; //License from project: LGPL import java.util.concurrent.TimeUnit; public class Main { /**/* ww w . ja va 2s. c o m*/ * Duration in the form - PTHH:mm:ss.mmm * P is period or duration and T designates * a time in ISO8601 format. * * @param date - created from milliseconds * @return - duration up to 24hrs max */ public static String formatDuration(long millis) { if (millis < 0) { throw new IllegalArgumentException(String.format("Duration: %d is < 0", millis)); } // long days = TimeUnit.MILLISECONDS.toDays(millis); // millis -= TimeUnit.DAYS.toMillis(days); long hours = TimeUnit.MILLISECONDS.toHours(millis); millis -= TimeUnit.HOURS.toMillis(hours); long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); millis -= TimeUnit.MINUTES.toMillis(minutes); long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); millis -= TimeUnit.SECONDS.toMillis(seconds); return String.format("PT%02d:%02d:%02d.%03d", hours, minutes, seconds, millis); } }