org.apache.commons.lang.time.FastDateFormat


 public class FastDateFormat extends java.text.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 has closed the bug/RFE.

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

Java 1.4 introduced a new pattern letter, 'Z', to represent time zones in RFC822 format (e.g., +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 (e.g., +08:00 or -11:00). This introduces a minor incompatability with Java 1.4, but at a gain of useful functionality.

Nested Class Summary

Nested classes inherited from class java.text.Format

 java.text.Format.Field 

Methods inherited from class java.text.Format

clone, format, formatToCharacterIterator, parseObject

Field Detail

 public static final int FULL 

FULL locale dependent date or time style.

 public static final int LONG 

LONG locale dependent date or time style.

 public static final int MEDIUM 

MEDIUM locale dependent date or time style.

 public static final int SHORT 

SHORT locale dependent date or time style.

Method Detail

 public static FastDateFormat getInstance() 

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

Returns: a date/time formatter

 public static FastDateFormat getInstance(java.lang.String pattern) 

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

Parameters: patternSimpleDateFormat compatible pattern

Returns: a pattern based date/time formatter

Throws: java.lang.IllegalArgumentExceptionif pattern is invalid

[View full width]

public static FastDateFormat getInstance(java.lang.String pattern, java.util.TimeZone timeZone)

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

Parameters: patternSimpleDateFormat compatible pattern

timeZoneoptional time zone, overrides time zone of formatted date

Returns: a pattern based date/time formatter

Throws: java.lang.IllegalArgumentExceptionif pattern is invalid

 public static FastDateFormat getInstance(java.lang.String pattern, java.util.Locale locale) 

Gets a formatter instance using the specified pattern and locale.

Parameters: patternSimpleDateFormat compatible pattern

localeoptional locale, overrides system locale

Returns: a pattern based date/time formatter

Throws: java.lang.IllegalArgumentExceptionif pattern is invalid

[View full width]

public static FastDateFormat getInstance(java.lang.String pattern, java.util.TimeZone timeZone, java.util.Locale locale)

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

Parameters: patternSimpleDateFormat compatible pattern

timeZoneoptional time zone, overrides time zone of formatted date

localeoptional locale, overrides system locale

Returns: a pattern based date/time formatter

Throws: java.lang.IllegalArgumentExceptionif pattern is invalid or null

[View full width]

public static FastDateFormat getDateInstance(int style, java.util.TimeZone timeZone, java .util.Locale locale)

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

Parameters: styledate style: FULL, LONG, MEDIUM, or SHORT

timeZoneoptional time zone, overrides time zone of formatted date

localeoptional locale, overrides system locale

Returns: a localized standard date formatter

Throws: java.lang.IllegalArgumentExceptionif the Locale has no date pattern defined

[View full width]

public static FastDateFormat getTimeInstance(int style, java.util.TimeZone timeZone, java .util.Locale locale)

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

Parameters: styletime style: FULL, LONG, MEDIUM, or SHORT

timeZoneoptional time zone, overrides time zone of formatted time

localeoptional locale, overrides system locale

Returns: a localized standard time formatter

Throws: java.lang.IllegalArgumentExceptionif the Locale has no time pattern defined

 public static FastDateFormat getDateTimeInstance(int dateStyle, int timeStyle, java.util.TimeZone timeZone, java.util.Locale locale) 

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

Parameters: dateStyledate style: FULL, LONG, MEDIUM, or SHORT

timeStyletime style: FULL, LONG, MEDIUM, or SHORT

timeZoneoptional time zone, overrides time zone of formatted date

localeoptional locale, overrides system locale

Returns: a localized standard date/time formatter

Throws: java.lang.IllegalArgumentExceptionif the Locale has no date/time pattern defined

 public java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos) 

Format either a Date or a Calendar object.

Parameters: objthe object to format

toAppendTothe buffer to append to

posthe positionignored

Returns: the buffer passed in

 public java.lang.String format(java.util.Date date) 

Formats a Date object.

Parameters: datethe date to format

Returns: the formatted string

 public java.lang.String format(java.util.Calendar calendar) 

Formats a Calendar object.

Parameters: calendarthe calendar to format

Returns: the formatted string

 public java.lang.StringBuffer format(java.util.Date date, java.lang.StringBuffer buf) 

Formats a Date object into the supplied StringBuffer.

Parameters: datethe date to format

bufthe buffer to format into

Returns: the specified string buffer

 public java.lang.StringBuffer format(java.util.Calendar calendar, java.lang.StringBuffer buf) 

Formats a Calendar object into the supplied StringBuffer.

Parameters: calendarthe calendar to format

bufthe buffer to format into

Returns: the specified string buffer

 public java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos) 

Parsing not supported.

Parameters: sourcethe string to parse

posthe parsing position

Returns: null as not supported

 public java.lang.String getPattern() 

Gets the pattern used by this formatter.

Returns: the pattern, SimpleDateFormat compatible

 public java.util.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().

Returns: the time zone

 public boolean getTimeZoneOverridesCalendar() 

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

Returns: TRue if time zone of formatter overridden for calendars

 public java.util.Locale getLocale() 

Gets the locale used by this formatter.

Returns: the locale

 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.

Returns: the maximum formatted length

 public boolean equals(java.lang.Object obj) 

Compare two objects for equality.

Parameters: objthe object to compare to

Returns: true if equal

 public int hashCode() 

A suitable hashcode.

Returns: a hashcode compatable with equals

 public java.lang.String toString() 

Gets a debugging string version of this formatter.

Returns: a debugging string



    Apache Jakarta Commons(c) Reusable Java Components
    Real World Web Services
    ISBN: N/A
    EAN: 2147483647
    Year: 2006
    Pages: 137
    Authors: Will Iverson

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net