Format Duration in Java

Description

The following code shows how to format Duration.

Example


/*ww w  . java 2 s. c  om*/
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class Main {

  public static String formatDuration(long duration) {
    SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss:SSS");
    format.setTimeZone(TimeZone.getTimeZone("GMT"));
    return format.format(new Date(duration));
  }

  public static void main(String[] argv) {
    System.out.println(formatDuration(123123));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Date »




Date Get
Date Set
Date Format
Date Compare
Date Convert
Date Calculation
Date Parse
Timezone