Here you can find the source of getDuration(final long millis)
Parameter | Description |
---|---|
millis | the duration in milliseconds. |
HH:mm:ss.SSS
.
public static String getDuration(final long millis)
//package com.java2s; /******************************************************************************* * Copyright (c) 2013, 2014, 2015 QPark Consulting S.a r.l. This program and the * accompanying materials are made available under the terms of the Eclipse * Public License v1.0. The Eclipse Public License is available at * http://www.eclipse.org/legal/epl-v10.html. ******************************************************************************/ import java.text.DecimalFormat; import java.util.Calendar; import java.util.TimeZone; public class Main { /**//ww w .j a v a 2s . c o m * @param millis * the duration in milliseconds. * @return a string with the duration formatted with * <code>HH:mm:ss.SSS</code>. */ public static String getDuration(final long millis) { DecimalFormat df20 = new DecimalFormat("00"); DecimalFormat df30 = new DecimalFormat("000"); Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC")); c.setTimeInMillis(millis); return new StringBuffer(12).append(df20.format(c.get(Calendar.HOUR_OF_DAY))).append(":") .append(df20.format(c.get(Calendar.MINUTE))).append(":").append(df20.format(c.get(Calendar.SECOND))) .append(".").append(df30.format(c.get(Calendar.MILLISECOND))).toString(); } }