|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.text.Format org.apache.commons.lang.time.FastDateFormat
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 incompatability with Java 1.4, but at a gain of
useful functionality.
Nested Class Summary |
Nested classes inherited from class java.text.Format |
Format.Field |
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 | |
protected |
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. |
String |
format(Calendar calendar)
Formats a Calendar object. |
StringBuffer |
format(Calendar calendar,
StringBuffer buf)
Formats a Calendar object into the
supplied StringBuffer . |
String |
format(Date date)
Formats a Date object. |
StringBuffer |
format(Date date,
StringBuffer buf)
Formats a Date object into the
supplied StringBuffer . |
StringBuffer |
format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos)
Format either a Date or a
Calendar object. |
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,
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,
Locale locale)
Gets a formatter instance using the specified pattern and locale. |
static FastDateFormat |
getInstance(String pattern,
TimeZone timeZone)
Gets a formatter instance using the specified pattern and time zone. |
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,
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 org.apache.commons.lang.time.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. |
Methods inherited from class java.text.Format |
clone, format, formatToCharacterIterator, parseObject |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int FULL
public static final int LONG
public static final int MEDIUM
public static final int SHORT
Constructor Detail |
protected FastDateFormat(String pattern, TimeZone timeZone, Locale locale)
Constructs a new FastDateFormat.
pattern
- SimpleDateFormat
compatible
patterntimeZone
- time zone to use, null
means use
default for Date
and value within for
Calendar
locale
- locale, null
means use system
default
IllegalArgumentException
- if pattern is invalid or
null
Method Detail |
public static FastDateFormat getInstance()
Gets a formatter instance using the default pattern in the default locale.
public static FastDateFormat getInstance(String pattern)
Gets a formatter instance using the specified pattern in the default locale.
pattern
- SimpleDateFormat
compatible
pattern
IllegalArgumentException
- if pattern is invalidpublic static FastDateFormat getInstance(String pattern, TimeZone timeZone)
Gets a formatter instance using the specified pattern and time zone.
pattern
- SimpleDateFormat
compatible
patterntimeZone
- optional time zone, overrides time zone of
formatted date
IllegalArgumentException
- if pattern is invalidpublic static FastDateFormat getInstance(String pattern, Locale locale)
Gets a formatter instance using the specified pattern and locale.
pattern
- SimpleDateFormat
compatible
patternlocale
- optional locale, overrides system locale
IllegalArgumentException
- if pattern is invalidpublic static FastDateFormat getInstance(String pattern, TimeZone timeZone, Locale locale)
Gets a formatter instance using the specified pattern, time zone and locale.
pattern
- SimpleDateFormat
compatible
patterntimeZone
- optional time zone, overrides time zone of
formatted datelocale
- optional locale, overrides system locale
IllegalArgumentException
- if pattern is invalid
or null
public static FastDateFormat getDateInstance(int style, TimeZone timeZone, Locale locale)
Gets a date formatter instance using the specified style, time zone and locale.
style
- date style: FULL, LONG, MEDIUM, or SHORTtimeZone
- optional time zone, overrides time zone of
formatted datelocale
- optional locale, overrides system locale
IllegalArgumentException
- if the Locale has no date
pattern definedpublic static FastDateFormat getTimeInstance(int style, TimeZone timeZone, Locale locale)
Gets a time formatter instance using the specified style, time zone and locale.
style
- time style: FULL, LONG, MEDIUM, or SHORTtimeZone
- optional time zone, overrides time zone of
formatted timelocale
- optional locale, overrides system locale
IllegalArgumentException
- if the Locale has no time
pattern definedpublic 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.
dateStyle
- date style: FULL, LONG, MEDIUM, or SHORTtimeStyle
- time style: FULL, LONG, MEDIUM, or SHORTtimeZone
- optional time zone, overrides time zone of
formatted datelocale
- optional locale, overrides system locale
IllegalArgumentException
- if the Locale has no date/time
pattern definedprotected void init()
Initialise the instance for first use.
protected List parsePattern()
Returns a list of Rules given a pattern.
List
of Rule objects
IllegalArgumentException
- if pattern is invalidprotected String parseToken(String pattern, int[] indexRef)
Performs the parsing of tokens.
pattern
- the patternindexRef
- index references
protected org.apache.commons.lang.time.FastDateFormat.NumberRule selectNumberRule(int field, int padding)
Gets an appropriate rule for the padding required.
field
- the field to get a rule forpadding
- the padding required
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
Format either a Date
or a
Calendar
object.
obj
- the object to formattoAppendTo
- the buffer to append topos
- the position - ignored
public String format(Date date)
Formats a Date
object.
date
- the date to format
public String format(Calendar calendar)
Formats a Calendar
object.
calendar
- the calendar to format
public StringBuffer format(Date date, StringBuffer buf)
Formats a Date
object into the
supplied StringBuffer
.
date
- the date to formatbuf
- the buffer to format into
public StringBuffer format(Calendar calendar, StringBuffer buf)
Formats a Calendar
object into the
supplied StringBuffer
.
calendar
- the calendar to formatbuf
- the buffer to format into
protected StringBuffer applyRules(Calendar calendar, StringBuffer buf)
Performs the formatting by applying the rules to the specified calendar.
calendar
- the calendar to formatbuf
- the buffer to format into
public Object parseObject(String source, ParsePosition pos)
Parsing not supported.
source
- the string to parsepos
- the parsing position
null
as not supportedpublic String getPattern()
Gets the pattern used by this formatter.
SimpleDateFormat
compatiblepublic 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()
.
public boolean getTimeZoneOverridesCalendar()
Returns true
if the time zone of the
calendar overrides the time zone of the formatter.
true
if time zone of formatter
overridden for calendarspublic Locale getLocale()
Gets the locale used by this formatter.
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.
public boolean equals(Object obj)
Compare two objects for equality.
obj
- the object to compare to
true
if equalpublic int hashCode()
A suitable hashcode.
public String toString()
Gets a debugging string version of this formatter.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |