Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.commons.lang.time
Class DurationFormatUtils  view DurationFormatUtils download DurationFormatUtils.java

java.lang.Object
  extended byorg.apache.commons.lang.time.DurationFormatUtils

public class DurationFormatUtils
extends java.lang.Object

Duration formatting utilities and constants. The following table describes the tokens used in the pattern language for formatting.

characterduration element
yyears
Mmonths
ddays
Hhours
mminutes
sseconds
Smilliseconds

Since:
2.1
Version:
$Id: DurationFormatUtils.java 165657 2005-05-02 18:31:49Z ggregory $

Nested Class Summary
(package private) static class DurationFormatUtils.Token
          Element that is parsed from the format pattern.
 
Field Summary
(package private) static java.lang.Object d
           
(package private) static java.lang.Object H
           
static java.lang.String ISO_EXTENDED_FORMAT_PATTERN
          Pattern used with FastDateFormat and SimpleDateFormat for the ISO8601 period format used in durations.
(package private) static java.lang.Object m
           
(package private) static java.lang.Object M
           
(package private) static java.lang.Object s
           
(package private) static java.lang.Object S
           
(package private) static java.lang.Object y
           
 
Constructor Summary
DurationFormatUtils()
          DurationFormatUtils instances should NOT be constructed in standard programming.
 
Method Summary
(package private) static java.lang.String format(DurationFormatUtils.Token[] tokens, int years, int months, int days, int hours, int minutes, int seconds, int milliseconds, boolean padWithZeros)
          The internal method to do the formatting.
static java.lang.String formatDuration(long durationMillis, java.lang.String format)
          Get the time gap as a string, using the specified format, and padding with zeros and using the default timezone.
static java.lang.String formatDuration(long durationMillis, java.lang.String format, boolean padWithZeros)
          Get the time gap as a string, using the specified format.
static java.lang.String formatDurationHMS(long durationMillis)
          Get the time gap as a string.
static java.lang.String formatDurationISO(long durationMillis)
          Get the time gap as a string.
static java.lang.String formatDurationWords(long durationMillis, boolean suppressLeadingZeroElements, boolean suppressTrailingZeroElements)
          Format an elapsed time into a plurialization correct string.
static java.lang.String formatPeriod(long startMillis, long endMillis, java.lang.String format)
          Get the time gap as a string, using the specified format.
static java.lang.String formatPeriod(long startMillis, long endMillis, java.lang.String format, boolean padWithZeros, java.util.TimeZone timezone)
          Get the time gap as a string, using the specified format.
static java.lang.String formatPeriodISO(long startMillis, long endMillis)
          Get the time gap as a string.
(package private) static DurationFormatUtils.Token[] lexx(java.lang.String format)
          Parse a classic date format string into Tokens
(package private) static int reduceAndCorrect(java.util.Calendar start, java.util.Calendar end, int field, int difference)
          Reduces by difference, then if it overshot, calculates the overshot amount and fixes and returns the amount to change by.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ISO_EXTENDED_FORMAT_PATTERN

public static final java.lang.String ISO_EXTENDED_FORMAT_PATTERN

Pattern used with FastDateFormat and SimpleDateFormat for the ISO8601 period format used in durations.

See Also:
FastDateFormat, java.text.SimpleDateFormat, Constant Field Values

y

static final java.lang.Object y

M

static final java.lang.Object M

d

static final java.lang.Object d

H

static final java.lang.Object H

m

static final java.lang.Object m

s

static final java.lang.Object s

S

static final java.lang.Object S
Constructor Detail

DurationFormatUtils

public DurationFormatUtils()

DurationFormatUtils instances should NOT be constructed in standard programming.

This constructor is public to permit tools that require a JavaBean instance to operate.

Method Detail

formatDurationHMS

public static java.lang.String formatDurationHMS(long durationMillis)

Get the time gap as a string.

The format used is ISO8601-like: H:m:s.S.


formatDurationISO

public static java.lang.String formatDurationISO(long durationMillis)

Get the time gap as a string.

The format used is the ISO8601 period format.

This method formats durations using the days and lower fields of the ISO format pattern, such as P7D6H5M4.321S.


formatDuration

public static java.lang.String formatDuration(long durationMillis,
                                              java.lang.String format)

Get the time gap as a string, using the specified format, and padding with zeros and using the default timezone.

This method formats durations using the days and lower fields of the format pattern. Months and larger are not used.


formatDuration

public static java.lang.String formatDuration(long durationMillis,
                                              java.lang.String format,
                                              boolean padWithZeros)

Get the time gap as a string, using the specified format. Padding the left hand side of numbers with zeroes is optional and the timezone may be specified.

This method formats durations using the days and lower fields of the format pattern. Months and larger are not used.


formatDurationWords

public static java.lang.String formatDurationWords(long durationMillis,
                                                   boolean suppressLeadingZeroElements,
                                                   boolean suppressTrailingZeroElements)

Format an elapsed time into a plurialization correct string.

This method formats durations using the days and lower fields of the format pattern. Months and larger are not used.


formatPeriodISO

public static java.lang.String formatPeriodISO(long startMillis,
                                               long endMillis)

Get the time gap as a string.

The format used is the ISO8601 period format.


formatPeriod

public static java.lang.String formatPeriod(long startMillis,
                                            long endMillis,
                                            java.lang.String format)

Get the time gap as a string, using the specified format. Padding the left hand side of numbers with zeroes is optional.


formatPeriod

public static java.lang.String formatPeriod(long startMillis,
                                            long endMillis,
                                            java.lang.String format,
                                            boolean padWithZeros,
                                            java.util.TimeZone timezone)

Get the time gap as a string, using the specified format. Padding the left hand side of numbers with zeroes is optional and the timezone may be specified.


format

static java.lang.String format(DurationFormatUtils.Token[] tokens,
                               int years,
                               int months,
                               int days,
                               int hours,
                               int minutes,
                               int seconds,
                               int milliseconds,
                               boolean padWithZeros)

The internal method to do the formatting.


reduceAndCorrect

static int reduceAndCorrect(java.util.Calendar start,
                            java.util.Calendar end,
                            int field,
                            int difference)
Reduces by difference, then if it overshot, calculates the overshot amount and fixes and returns the amount to change by.


lexx

static DurationFormatUtils.Token[] lexx(java.lang.String format)
Parse a classic date format string into Tokens