Java Duration Format formatDuration(long milliseconds)

Here you can find the source of formatDuration(long milliseconds)

Description

Format a time duration as "hh:mm:ss"

License

Open Source License

Parameter

Parameter Description
milliseconds Time duration in milliseconds

Return

Formated time duration.

Declaration


public static String formatDuration(long milliseconds) 

Method Source Code

//package com.java2s;
/*   Please see the license information at the end of this file. */

public class Main {
    /**   Format a time duration as "hh:mm:ss"
     *//w  ww  . ja  v  a  2s. co  m
     *   @param   milliseconds   Time duration in milliseconds
     *
     *   @return               Formated time duration.
     */

    public static String formatDuration(long milliseconds) {
        long seconds = milliseconds / 1000;
        long hours = seconds / 3600;
        seconds -= hours * 3600;
        long minutes = seconds / 60;
        seconds -= minutes * 60;
        return (hours < 10 ? "0" : "") + hours + ":" + (minutes < 10 ? "0" : "") + minutes + ":"
                + (seconds < 10 ? "0" : "") + seconds;
    }
}

Related

  1. formatDuration(long elapsedSec)
  2. formatDuration(Long input)
  3. formatDuration(long milis)
  4. formatDuration(long millis)
  5. formatDuration(long millis)
  6. formatDuration(long milliseconds)
  7. formatDuration(long ms)
  8. formatDuration(long ms)
  9. formatDuration(long number)