public class IlvDateFormat extends DateFormat
IlvDateFormat is a compatible replacement for the standard
SimpleDateFormat class. It automatically uses ICU
SimpleDateFormat when appropriate (namely, in a Polish locale or
when the format pattern includes pattern characters like e for
the day in the week). It also automatically detects if the
FastDateFormat class from the
Jakarta Commons Lang
package is on the classpath. If so, IlvDateFormat transparently
takes advantage of this and provides a significant speed improvement for
formatted output. Although you can directly create instances of
IlvDateFormat, you can achieve even better performance by
creating instances via IlvDateFormatFactory. This factory implements
caching techniques to improve the speed of creating format instances.
IlvDateFormat is compatible with the formatting styles of
DateFormat and with the formatting patterns of
SimpleDateFormat and
com.ibm.icu.text.SimpleDateFormat. However, some this
class's speed improvements derive from the fact that it treats certain
attributes as immutable, in contrast to its DateFormat
superclass. The following attributes of IlvDateFormat are
immutable and attempting to change their value will result in an
UnsupportedOperationException:
IlvDateFormatFactory,
Serialized FormDateFormat.FieldAM_PM_FIELD, calendar, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, numberFormat, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD| Constructor and Description |
|---|
IlvDateFormat(int dateStyle,
int timeStyle,
Locale locale,
TimeZone timeZone)
Deprecated.
This method ignores the calendar specification in the
ULocale. Please use
IlvDateFormat(int, int, ULocale, TimeZone) instead. |
IlvDateFormat(int dateStyle,
int timeStyle,
ULocale locale,
TimeZone timeZone)
Returns a formatter with the given date and time styles for the given
locale and timezone.
|
IlvDateFormat(String pattern,
ULocale locale,
TimeZone timeZone)
Creates a date/time formatter using the specified pattern for the given
locale and timezone.
|
IlvDateFormat(ULocale locale)
Creates a default date/time formatter that uses the
DateFormat.SHORT style
for both the date and the time in the given locale and the default
timezone. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj)
Returns whether an object is logically equal to this date format.
|
StringBuffer |
format(Date date,
StringBuffer toAppendTo,
FieldPosition fieldPosition)
Formats a date into a date/time string.
|
Calendar |
getCalendar()
Returns the calendar associated with this date/time formatter.
|
Locale |
getLocale()
Returns the locale.
|
NumberFormat |
getNumberFormat()
Returns the number formatter which this date/time formatter uses to format
and parse a time.
|
TimeZone |
getTimeZone()
Returns the time zone.
|
ULocale |
getULocale()
Returns the locale.
|
int |
hashCode()
Returns a hashcode for this format.
|
boolean |
isLenient()
Returns whether date/time parsing is lenient.
|
Date |
parse(String source,
ParsePosition pos)
Parses text from a string to produce a
Date. |
static void |
registerPreferenceForICU(String language)
Registers a preference for ICU based formatting instead of JRE based
formatting for the given language.
|
void |
setCalendar(Calendar calendar)
Sets the calendar to be used by this date format.
|
void |
setLenient(boolean lenient)
Specifies whether or not date/time parsing is to be lenient.
|
void |
setNumberFormat(NumberFormat numberFormat)
Sets the number formatter.
|
void |
setTimeZone(TimeZone zone)
Sets the time zone for the calendar of this DateFormat object.
|
String |
toPattern()
Returns a
SimpleDateFormat or
com.ibm.icu.text.SimpleDateFormat compatible pattern
string describing this date format. |
clone, format, format, getAvailableLocales, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getTimeInstance, getTimeInstance, getTimeInstance, parse, parseObjectformat, formatToCharacterIterator, parseObjectpublic IlvDateFormat(ULocale locale)
DateFormat.SHORT style
for both the date and the time in the given locale and the default
timezone.public IlvDateFormat(String pattern, ULocale locale, TimeZone timeZone)
pattern - A SimpleDateFormat or
com.ibm.icu.text.SimpleDateFormat compatible
pattern.locale - The locale or null for the default locale.timeZone - The timezone or null for the default timezone.IllegalArgumentException - if the pattern is invalid.@Deprecated public IlvDateFormat(int dateStyle, int timeStyle, Locale locale, TimeZone timeZone)
ULocale. Please use
IlvDateFormat(int, int, ULocale, TimeZone) instead.dateStyle - The date style. The value must be one of DateFormat.SHORT,
DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL, DateFormat.DEFAULT,
or -1. If -1, then a time formatter is created and dates will not
be formatted. For example, use DateFormat.SHORT for "M/d/yy" in the
US locale.timeStyle - The time style. The value must be one of DateFormat.SHORT,
DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL, DateFormat.DEFAULT,
or -1. If -1, then a date formatter is created and times will not
be formatted. For example, use DateFormat.SHORT for "h:mm a" in the
US locale.locale - The locale or null for the default locale.timeZone - The timezone or null for the default timezone.public IlvDateFormat(int dateStyle,
int timeStyle,
ULocale locale,
TimeZone timeZone)
dateStyle - The date style. The value must be one of DateFormat.SHORT,
DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL, DateFormat.DEFAULT,
or -1. If -1, then a time formatter is created and dates will not
be formatted. For example, use DateFormat.SHORT for "M/d/yy" in the
US locale.timeStyle - The time style. The value must be one of DateFormat.SHORT,
DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL, DateFormat.DEFAULT,
or -1. If -1, then a date formatter is created and times will not
be formatted. For example, use DateFormat.SHORT for "h:mm a" in the
US locale.locale - The locale or null for the default locale.timeZone - The timezone or null for the default timezone.public static void registerPreferenceForICU(String language)
language - An ISO 639
language code.public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition)
format in class DateFormatdate - The date to be formatted.toAppendTo - The buffer to append the formatted string.fieldPosition - This parameter is ignored.public Date parse(String source, ParsePosition pos)
Date. This method
attempts to parse text starting at the index given by pos. If
parsing succeeds, then the index of pos is updated to the
index after the last character used (parsing does not necessarily use all
characters up to the end of the string), and the parsed date is returned.
The updated pos can be used to indicate the starting point for
the next call to this method. If an error occurs, then the index of
pos is not changed, the error index of pos is set
to the index of the character where the error occurred, and null is
returned.parse in class DateFormatsource - The source text, part of which should be parsed.pos - A ParsePosition object with index and error index
information as described above.Date parsed from the string. In case of error,
returns null or throws a NumberFormatException.public Locale getLocale()
public ULocale getULocale()
public String toPattern()
SimpleDateFormat or
com.ibm.icu.text.SimpleDateFormat compatible pattern
string describing this date format.public void setCalendar(Calendar calendar)
UnsupportedOperationException because
IlvDateFormat objects consider the calendar to be immutable.setCalendar in class DateFormatcalendar - The new calendar to be used by the date format.UnsupportedOperationException - because IlvDateFormat objects consider the calendar
to be immutable.public Calendar getCalendar()
getCalendar in class DateFormatpublic void setNumberFormat(NumberFormat numberFormat)
UnsupportedOperationException because
IlvDateFormat objects consider the number format to be
immutable.setNumberFormat in class DateFormatnumberFormat - The new number format.UnsupportedOperationException - because IlvDateFormat objects consider the number
format to be immutable.public NumberFormat getNumberFormat()
getNumberFormat in class DateFormatpublic void setTimeZone(TimeZone zone)
UnsupportedOperationException because
IlvDateFormat objects consider the timezone to be immutable.setTimeZone in class DateFormatzone - The new time zone.UnsupportedOperationException - because IlvDateFormat objects consider the timezone
to be immutable.public TimeZone getTimeZone()
getTimeZone in class DateFormatpublic void setLenient(boolean lenient)
setLenient in class DateFormatlenient - Indicates whether parsing is lenient.public boolean isLenient()
isLenient in class DateFormatpublic boolean equals(Object obj)
equals in class DateFormatobj - The object to compare with.true if the object is equal to this format;
false otherwise.public int hashCode()
hashCode in class DateFormat© Copyright Rogue Wave Software, Inc. 1997, 2017. All Rights Reserved.