Java Millisecond Convert getDuration(final long millis)

Here you can find the source of getDuration(final long millis)

Description

get Duration

License

Open Source License

Parameter

Parameter Description
millis the duration in milliseconds.

Return

a string with the duration formatted with HH:mm:ss.SSS.

Declaration

public static String getDuration(final long millis) 

Method Source Code

//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();
    }
}

Related

  1. convertTimeMillisToHexString(long currentDate)
  2. convertTimeToDurationMilliseconds(String time)
  3. convertToMillis(float timeInSeconds)
  4. convertToMillis(String time)
  5. convertToMilliseconds(String value)
  6. getDurationBreakdown(long durationInMillis)
  7. getDurationMillisecond(Date date1, Date date2)
  8. getHumanDisplayForTimediff(Long diffMillis)
  9. getNice(long timeMillisecGMT)