org.apache.commons.lang.time
Class FastDateFormat

public class FastDateFormat
extends Format

FastDateFormat is a fast and thread-safe version of SimpleDateFormat .

This class can be used as a direct replacement to SimpleDateFormat in most formatting situations. This class is especially useful in multi-threaded server environments. SimpleDateFormat is not thread-safe in any JDK version, nor will it be as Sun have closed the bug/RFE.

Only formatting is supported, but all patterns are compatible with SimpleDateFormat (except time zones - see below).

Java 1.4 introduced a new pattern letter, 'Z', to represent time zones in RFC822 format (eg. +0800 or -1100). This pattern letter can be used here (on all JDK versions).

In addition, the pattern 'ZZ' has been made to represent ISO8601 full format time zones (eg. +08:00 or -11:00). This introduces a minor incompatibility with Java 1.4, but at a gain of useful functionality.

Since2.0
Version$Id: FastD
AuthorTeaTrove project, Brian S O'Neill, Sean Schofield, Gary Gregory, Stephen Colebourne, Nikolay Metchev
Wiki javadoc Use textile entry format.
Add your comments here.
Field Summary
static int FULL
FULL locale dependent date or time style.
static int LONG
LONG locale dependent date or time style.
static int MEDIUM
MEDIUM locale dependent date or time style.
static int SHORT
SHORT locale dependent date or time style.
Constructor Summary
FastDateFormat( String pattern, TimeZone timeZone, Locale locale )

Constructs a new FastDateFormat.

Method Summary
protected StringBuffer applyRules( Calendar calendar, StringBuffer buf )

Performs the formatting by applying the rules to the specified calendar.

boolean equals( Object obj )

Compare two objects for equality.

StringBuffer format( Object obj, StringBuffer toAppendTo, FieldPosition pos )

Formats a Date, Calendar or Long (milliseconds) object.

String format( long millis )

Formats a millisecond long value.

String format( Date date )

Formats a Date object.

String format( Calendar calendar )

Formats a Calendar object.

StringBuffer format( long millis, StringBuffer buf )

Formats a milliseond long value into the supplied StringBuffer.

StringBuffer format( Date date, StringBuffer buf )

Formats a Date object into the supplied StringBuffer.

StringBuffer format( Calendar calendar, StringBuffer buf )

Formats a Calendar object into the supplied StringBuffer.

static FastDateFormat getDateInstance( int style )

Gets a date formatter instance using the specified style in the default time zone and locale.

static FastDateFormat getDateInstance( int style, Locale locale )

Gets a date formatter instance using the specified style and locale in the default time zone.

static FastDateFormat getDateInstance( int style, TimeZone timeZone )

Gets a date formatter instance using the specified style and time zone in the default locale.

static FastDateFormat getDateInstance( int style, TimeZone timeZone, Locale locale )

Gets a date formatter instance using the specified style, time zone and locale.

static FastDateFormat getDateTimeInstance( int dateStyle, int timeStyle )

Gets a date/time formatter instance using the specified style in the default time zone and locale.

static FastDateFormat getDateTimeInstance( int dateStyle, int timeStyle, Locale locale )

Gets a date/time formatter instance using the specified style and locale in the default time zone.

static FastDateFormat getDateTimeInstance( int dateStyle, int timeStyle, TimeZone timeZone )

Gets a date/time formatter instance using the specified style and time zone in the default locale.

static FastDateFormat getDateTimeInstance( int dateStyle, int timeStyle, TimeZone timeZone, Locale locale )

Gets a date/time formatter instance using the specified style, time zone and locale.

static FastDateFormat getInstance()

Gets a formatter instance using the default pattern in the default locale.

static FastDateFormat getInstance( String pattern )

Gets a formatter instance using the specified pattern in the default locale.

static FastDateFormat getInstance( String pattern, TimeZone timeZone )

Gets a formatter instance using the specified pattern and time zone.

static FastDateFormat getInstance( String pattern, Locale locale )

Gets a formatter instance using the specified pattern and locale.

static FastDateFormat getInstance( String pattern, TimeZone timeZone, Locale locale )

Gets a formatter instance using the specified pattern, time zone and locale.

Locale getLocale()

Gets the locale used by this formatter.

int getMaxLengthEstimate()

Gets an estimate for the maximum string length that the formatter will produce.

String getPattern()

Gets the pattern used by this formatter.

static FastDateFormat getTimeInstance( int style )

Gets a time formatter instance using the specified style in the default time zone and locale.

static FastDateFormat getTimeInstance( int style, Locale locale )

Gets a time formatter instance using the specified style and locale in the default time zone.

static FastDateFormat getTimeInstance( int style, TimeZone timeZone )

Gets a time formatter instance using the specified style and time zone in the default locale.

static FastDateFormat getTimeInstance( int style, TimeZone timeZone, Locale locale )

Gets a time formatter instance using the specified style, time zone and locale.

TimeZone getTimeZone()

Gets the time zone used by this formatter.

boolean getTimeZoneOverridesCalendar()

Returns true if the time zone of the calendar overrides the time zone of the formatter.

int hashCode()

A suitable hashcode.

protected void init()

Initialise the instance for first use.

Object parseObject( String source, ParsePosition pos )

Parsing not supported.

protected List parsePattern()

Returns a list of Rules given a pattern.

protected String parseToken( String pattern, int [] indexRef )

Performs the parsing of tokens.

protected FastDateFormat.NumberRule selectNumberRule( int field, int padding )

Gets an appropriate rule for the padding required.

String toString()

Gets a debugging string version of this formatter.

FULL
public static int FULL
FULL locale dependent date or time style.
Wiki javadoc Use textile entry format.
Add your comments here.
LONG
public static int LONG
LONG locale dependent date or time style.
Wiki javadoc Use textile entry format.
Add your comments here.
MEDIUM
public static int MEDIUM
MEDIUM locale dependent date or time style.
Wiki javadoc Use textile entry format.
Add your comments here.
SHORT
public static int SHORT
SHORT locale dependent date or time style.
Wiki javadoc Use textile entry format.
Add your comments here.
FastDateFormat
protected FastDateFormat ( String pattern, TimeZone timeZone, Locale locale )

Constructs a new FastDateFormat.

Parameters
TypeNameDescription
String pattern SimpleDateFormat compatible pattern
TimeZone timeZone time zone to use, null means use default for Date and value within for Calendar
Locale locale locale, null means use system default
Wiki javadoc Use textile entry format.
Add your comments here.
applyRules
protected StringBuffer applyRules ( Calendar calendar, StringBuffer buf )

Performs the formatting by applying the rules to the specified calendar.

Parameters
TypeNameDescription
Calendar calendar the calendar to format
StringBuffer buf the buffer to format into
Wiki javadoc Use textile entry format.
Add your comments here.
equals
public boolean equals ( Object obj )

Compare two objects for equality.

Overrides method in Object
Parameters
TypeNameDescription
Object obj the object to compare to
Wiki javadoc Use textile entry format.
Add your comments here.
format
public StringBuffer format ( Object obj, StringBuffer toAppendTo, FieldPosition pos )

Formats a Date, Calendar or Long (milliseconds) object.

Overrides method in Format
Parameters
TypeNameDescription
Object obj the object to format
StringBuffer toAppendTo the buffer to append to
FieldPosition pos the position - ignored
Wiki javadoc Use textile entry format.
Add your comments here.
format
public String format ( long millis )

Formats a millisecond long value.

Since: 2.1
Parameters
TypeNameDescription
long millis the millisecond value to format
Wiki javadoc Use textile entry format.
Add your comments here.
format
public String format ( Date date )

Formats a Date object.

Parameters
TypeNameDescription
Date date the date to format
Wiki javadoc Use textile entry format.
Add your comments here.
format
public String format ( Calendar calendar )

Formats a Calendar object.

Parameters
TypeNameDescription
Calendar calendar the calendar to format
Wiki javadoc Use textile entry format.
Add your comments here.
format
public StringBuffer format ( long millis, StringBuffer buf )

Formats a milliseond long value into the supplied StringBuffer.

Since: 2.1
Parameters
TypeNameDescription
long millis the millisecond value to format
StringBuffer buf the buffer to format into
Wiki javadoc Use textile entry format.
Add your comments here.
format
public StringBuffer format ( Date date, StringBuffer buf )

Formats a Date object into the supplied StringBuffer.

Parameters
TypeNameDescription
Date date the date to format
StringBuffer buf the buffer to format into
Wiki javadoc Use textile entry format.
Add your comments here.
format
public StringBuffer format ( Calendar calendar, StringBuffer buf )

Formats a Calendar object into the supplied StringBuffer.

Parameters
TypeNameDescription
Calendar calendar the calendar to format
StringBuffer buf the buffer to format into
Wiki javadoc Use textile entry format.
Add your comments here.
getDateInstance
public static FastDateFormat getDateInstance ( int style )

Gets a date formatter instance using the specified style in the default time zone and locale.

Since: 2.1
Parameters
TypeNameDescription
int style date style: FULL, LONG, MEDIUM, or SHORT
Wiki javadoc Use textile entry format.
Add your comments here.
getDateInstance
public static FastDateFormat getDateInstance ( int style, Locale locale )

Gets a date formatter instance using the specified style and locale in the default time zone.

Since: 2.1
Parameters
TypeNameDescription
int style date style: FULL, LONG, MEDIUM, or SHORT
Locale locale optional locale, overrides system locale
Wiki javadoc Use textile entry format.
Add your comments here.
getDateInstance
public static FastDateFormat getDateInstance ( int style, TimeZone timeZone )

Gets a date formatter instance using the specified style and time zone in the default locale.

Since: 2.1
Parameters
TypeNameDescription
int style date style: FULL, LONG, MEDIUM, or SHORT
TimeZone timeZone optional time zone, overrides time zone of formatted date
Wiki javadoc Use textile entry format.
Add your comments here.
getDateInstance
public static FastDateFormat getDateInstance ( int style, TimeZone timeZone, Locale locale )

Gets a date formatter instance using the specified style, time zone and locale.

Parameters
TypeNameDescription
int style date style: FULL, LONG, MEDIUM, or SHORT
TimeZone timeZone optional time zone, overrides time zone of formatted date
Locale locale optional locale, overrides system locale
Wiki javadoc Use textile entry format.
Add your comments here.
getDateTimeInstance
public static FastDateFormat getDateTimeInstance ( int dateStyle, int timeStyle )

Gets a date/time formatter instance using the specified style in the default time zone and locale.

Since: 2.1
Parameters
TypeNameDescription
int dateStyle date style: FULL, LONG, MEDIUM, or SHORT
int timeStyle time style: FULL, LONG, MEDIUM, or SHORT
Wiki javadoc Use textile entry format.
Add your comments here.
getDateTimeInstance
public static FastDateFormat getDateTimeInstance ( int dateStyle, int timeStyle, Locale locale )

Gets a date/time formatter instance using the specified style and locale in the default time zone.

Since: 2.1
Parameters
TypeNameDescription
int dateStyle date style: FULL, LONG, MEDIUM, or SHORT
int timeStyle time style: FULL, LONG, MEDIUM, or SHORT
Locale locale optional locale, overrides system locale
Wiki javadoc Use textile entry format.
Add your comments here.
getDateTimeInstance
public static FastDateFormat getDateTimeInstance ( int dateStyle, int timeStyle, TimeZone timeZone )

Gets a date/time formatter instance using the specified style and time zone in the default locale.

Since: 2.1
Parameters
TypeNameDescription
int dateStyle date style: FULL, LONG, MEDIUM, or SHORT
int timeStyle time style: FULL, LONG, MEDIUM, or SHORT
TimeZone timeZone optional time zone, overrides time zone of formatted date
Wiki javadoc Use textile entry format.
Add your comments here.
getDateTimeInstance
public static FastDateFormat getDateTimeInstance ( int dateStyle, int timeStyle, TimeZone timeZone, Locale locale )

Gets a date/time formatter instance using the specified style, time zone and locale.

Parameters
TypeNameDescription
int dateStyle date style: FULL, LONG, MEDIUM, or SHORT
int timeStyle time style: FULL, LONG, MEDIUM, or SHORT
TimeZone timeZone optional time zone, overrides time zone of formatted date
Locale locale optional locale, overrides system locale
Wiki javadoc Use textile entry format.
Add your comments here.
getInstance
public static FastDateFormat getInstance ( )

Gets a formatter instance using the default pattern in the default locale.

Wiki javadoc Use textile entry format.
Add your comments here.
getInstance
public static FastDateFormat getInstance ( String pattern )

Gets a formatter instance using the specified pattern in the default locale.

Parameters
TypeNameDescription
String pattern SimpleDateFormat compatible pattern
Wiki javadoc Use textile entry format.
Add your comments here.
getInstance
public static FastDateFormat getInstance ( String pattern, TimeZone timeZone )

Gets a formatter instance using the specified pattern and time zone.

Parameters
TypeNameDescription
String pattern SimpleDateFormat compatible pattern
TimeZone timeZone optional time zone, overrides time zone of formatted date
Wiki javadoc Use textile entry format.
Add your comments here.
getInstance
public static FastDateFormat getInstance ( String pattern, Locale locale )

Gets a formatter instance using the specified pattern and locale.

Parameters
TypeNameDescription
String pattern SimpleDateFormat compatible pattern
Locale locale optional locale, overrides system locale
Wiki javadoc Use textile entry format.
Add your comments here.
getInstance
public static FastDateFormat getInstance ( String pattern, TimeZone timeZone, Locale locale )

Gets a formatter instance using the specified pattern, time zone and locale.

Parameters
TypeNameDescription
String pattern SimpleDateFormat compatible pattern
TimeZone timeZone optional time zone, overrides time zone of formatted date
Locale locale optional locale, overrides system locale
Wiki javadoc Use textile entry format.
Add your comments here.
getLocale
public Locale getLocale ( )

Gets the locale used by this formatter.

Wiki javadoc Use textile entry format.
Add your comments here.
getMaxLengthEstimate
public int getMaxLengthEstimate ( )

Gets an estimate for the maximum string length that the formatter will produce.

The actual formatted length will almost always be less than or equal to this amount.

Wiki javadoc Use textile entry format.
Add your comments here.
getPattern
public String getPattern ( )

Gets the pattern used by this formatter.

Wiki javadoc Use textile entry format.
Add your comments here.
getTimeInstance
public static FastDateFormat getTimeInstance ( int style )

Gets a time formatter instance using the specified style in the default time zone and locale.

Since: 2.1
Parameters
TypeNameDescription
int style time style: FULL, LONG, MEDIUM, or SHORT
Wiki javadoc Use textile entry format.
Add your comments here.
getTimeInstance
public static FastDateFormat getTimeInstance ( int style, Locale locale )

Gets a time formatter instance using the specified style and locale in the default time zone.

Since: 2.1
Parameters
TypeNameDescription
int style time style: FULL, LONG, MEDIUM, or SHORT
Locale locale optional locale, overrides system locale
Wiki javadoc Use textile entry format.
Add your comments here.
getTimeInstance
public static FastDateFormat getTimeInstance ( int style, TimeZone timeZone )

Gets a time formatter instance using the specified style and time zone in the default locale.

Since: 2.1
Parameters
TypeNameDescription
int style time style: FULL, LONG, MEDIUM, or SHORT
TimeZone timeZone optional time zone, overrides time zone of formatted time
Wiki javadoc Use textile entry format.
Add your comments here.
getTimeInstance
public static FastDateFormat getTimeInstance ( int style, TimeZone timeZone, Locale locale )

Gets a time formatter instance using the specified style, time zone and locale.

Parameters
TypeNameDescription
int style time style: FULL, LONG, MEDIUM, or SHORT
TimeZone timeZone optional time zone, overrides time zone of formatted time
Locale locale optional locale, overrides system locale
Wiki javadoc Use textile entry format.
Add your comments here.
getTimeZone
public TimeZone getTimeZone ( )

Gets the time zone used by this formatter.

This zone is always used for Date formatting. If a Calendar is passed in to be formatted, the time zone on that may be used depending on getTimeZoneOverridesCalendar() .

Wiki javadoc Use textile entry format.
Add your comments here.
getTimeZoneOverridesCalendar
public boolean getTimeZoneOverridesCalendar ( )

Returns true if the time zone of the calendar overrides the time zone of the formatter.

Wiki javadoc Use textile entry format.
Add your comments here.
hashCode
public int hashCode ( )

A suitable hashcode.

Overrides method in Object
Wiki javadoc Use textile entry format.
Add your comments here.
init
protected void init ( )

Initialise the instance for first use.

Returns void No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
parseObject
public Object parseObject ( String source, ParsePosition pos )

Parsing not supported.

Overrides method in Format
Parameters
TypeNameDescription
String source the string to parse
ParsePosition pos the parsing position
Wiki javadoc Use textile entry format.
Add your comments here.
parsePattern
protected List parsePattern ( )

Returns a list of Rules given a pattern.

Wiki javadoc Use textile entry format.
Add your comments here.
parseToken
protected String parseToken ( String pattern, int [] indexRef )

Performs the parsing of tokens.

Parameters
TypeNameDescription
String pattern the pattern
int[] indexRef index references
Wiki javadoc Use textile entry format.
Add your comments here.
selectNumberRule
protected FastDateFormat.NumberRule selectNumberRule ( int field, int padding )

Gets an appropriate rule for the padding required.

Parameters
TypeNameDescription
int field the field to get a rule for
int padding the padding required
Wiki javadoc Use textile entry format.
Add your comments here.
toString
public String toString ( )

Gets a debugging string version of this formatter.

Overrides method in Object
Wiki javadoc Use textile entry format.
Add your comments here.