DateFormatSymbols is a public class for encapsulating
localizable date-time formatting data, such as the names of the
months, the names of the days of the week, and the time zone data.
DateFormat and
SimpleDateFormat both use
DateFormatSymbols to encapsulate this information.
Typically you shouldn't use DateFormatSymbols directly.
Rather, you are encouraged to create a date-time formatter with the
DateFormat class's factory methods: getTimeInstance,
getDateInstance, or getDateTimeInstance.
These methods automatically create a DateFormatSymbols for
the formatter so that you don't have to. After the
formatter is created, you may modify its format pattern using the
setPattern method. For more information about
creating formatters using DateFormat's factory methods,
see DateFormat.
If you decide to create a date-time formatter with a specific
format pattern for a specific locale, you can do so with:
new SimpleDateFormat(aPattern, DateFormatSymbols.getInstance(aLocale)).
DateFormatSymbols objects are cloneable. When you obtain
a DateFormatSymbols object, feel free to modify the
date-time formatting data. For instance, you can replace the localized
date-time format pattern characters with the ones that you feel easy
to remember. Or you can change the representative cities
to your favorite ones.
New DateFormatSymbols subclasses may be added to support
SimpleDateFormat for date-time formatting for additional locales.
Construct a DateFormatSymbols object by loading format data from
resources for the default locale. This constructor can only
construct instances for the locales supported by the Java
runtime environment, not for those supported by installed
DateFormatSymbolsProvider
implementations. For full locale coverage, use the
getInstance method.
Construct a DateFormatSymbols object by loading format data from
resources for the given locale. This constructor can only
construct instances for the locales supported by the Java
runtime environment, not for those supported by installed
DateFormatSymbolsProvider
implementations. For full locale coverage, use the
getInstance method.
Era strings. For example: "AD" and "BC". An array of 2 strings,
indexed by
Calendar.BC and
Calendar.AD.
Month strings. For example: "January", "February", etc. An array
of 13 strings (some calendars have 13 months), indexed by
Calendar.JANUARY,
Calendar.FEBRUARY, etc.
Short month strings. For example: "Jan", "Feb", etc. An array of
13 strings (some calendars have 13 months), indexed by
Calendar.JANUARY,
Calendar.FEBRUARY, etc.
Weekday strings. For example: "Sunday", "Monday", etc. An array
of 8 strings, indexed by
Calendar.SUNDAY,
Calendar.MONDAY, etc.
The element
weekdays[0] is ignored.
Short weekday strings. For example: "Sun", "Mon", etc. An array
of 8 strings, indexed by
Calendar.SUNDAY,
Calendar.MONDAY, etc.
The element
shortWeekdays[0] is ignored.
AM and PM strings. For example: "AM" and "PM". An array of
2 strings, indexed by
Calendar.AM and
Calendar.PM.
Localized names of time zones in this locale. This is a
two-dimensional array of strings of size
n by
m,
where
m is at least 5. Each of the
n rows is an
entry containing the localized names for a single
TimeZone.
Each such row contains (with
i ranging from
0..
n-1):
zoneStrings[i][0] - time zone ID
zoneStrings[i][1] - long name of zone in standard
time
zoneStrings[i][2] - short name of zone in
standard time
zoneStrings[i][3] - long name of zone in daylight
saving time
zoneStrings[i][4] - short name of zone in daylight
saving time
The zone ID is
not localized; it's one of the valid IDs of
the
TimeZone class that are not
custom IDs.
All other entries are localized names.
Indicates that zoneStrings is set externally with setZoneStrings() method.
Unlocalized date-time pattern characters. For example: 'y', 'd', etc.
All locales use the same these unlocalized pattern characters.
Localized date-time pattern characters. For example, a locale may
wish to use 'u' rather than 'y' to represent years in its date format
pattern strings.
This string must be exactly 18 characters long, with the index of
the characters described by
DateFormat.ERA_FIELD,
DateFormat.YEAR_FIELD, etc. Thus, if the string were
"Xz...", then localized patterns would use 'X' for era and 'z' for year.
The locale which is used for initializing this DateFormatSymbols object.
Returns an array of all locales for which the
getInstance methods of this class can return
localized instances.
The returned array represents the union of locales supported by the
Java runtime and by installed
DateFormatSymbolsProvider
implementations. It must contain at least a
Locale
instance equal to
Locale.US.
- Returns:
- An array of locales for which localized
DateFormatSymbols instances are available. - Since:
- 1.6
Gets the
DateFormatSymbols instance for the default
locale. This method provides access to
DateFormatSymbols
instances for locales supported by the Java runtime itself as well
as for those supported by installed
DateFormatSymbolsProvider
implementations.
- Returns:
- a
DateFormatSymbols instance. - Since:
- 1.6
Gets the
DateFormatSymbols instance for the specified
locale. This method provides access to
DateFormatSymbols
instances for locales supported by the Java runtime itself as well
as for those supported by installed
DateFormatSymbolsProvider
implementations.
if (providersInstance != null) { return providersInstance;
Gets era strings. For example: "AD" and "BC".
Sets era strings. For example: "AD" and "BC".
- Parameters:
newEras the new era strings.
Gets month strings. For example: "January", "February", etc.
- Returns:
- the month strings.
Sets month strings. For example: "January", "February", etc.
- Parameters:
newMonths the new month strings.
Gets short month strings. For example: "Jan", "Feb", etc.
- Returns:
- the short month strings.
Sets short month strings. For example: "Jan", "Feb", etc.
- Parameters:
newShortMonths the new short month strings.
Gets weekday strings. For example: "Sunday", "Monday", etc.
- Returns:
- the weekday strings. Use
Calendar.SUNDAY,
Calendar.MONDAY, etc. to index the result array.
Sets weekday strings. For example: "Sunday", "Monday", etc.
- Parameters:
newWeekdays the new weekday strings. The array should
be indexed by Calendar.SUNDAY,
Calendar.MONDAY, etc.
Gets short weekday strings. For example: "Sun", "Mon", etc.
- Returns:
- the short weekday strings. Use
Calendar.SUNDAY,
Calendar.MONDAY, etc. to index the result array.
Sets short weekday strings. For example: "Sun", "Mon", etc.
- Parameters:
newShortWeekdays the new short weekday strings. The array should
be indexed by Calendar.SUNDAY,
Calendar.MONDAY, etc.
Gets ampm strings. For example: "AM" and "PM".
- Returns:
- the ampm strings.
Sets ampm strings. For example: "AM" and "PM".
- Parameters:
newAmpms the new ampm strings.
Gets time zone strings. Use of this method is discouraged; use
TimeZone.getDisplayName()
instead.
The value returned is a
two-dimensional array of strings of size n by m,
where m is at least 5. Each of the n rows is an
entry containing the localized names for a single TimeZone.
Each such row contains (with i ranging from
0..n-1):
zoneStrings[i][0] - time zone ID
zoneStrings[i][1] - long name of zone in standard
time
zoneStrings[i][2] - short name of zone in
standard time
zoneStrings[i][3] - long name of zone in daylight
saving time
zoneStrings[i][4] - short name of zone in daylight
saving time
The zone ID is
not localized; it's one of the valid IDs of
the
TimeZone class that are not
custom IDs.
All other entries are localized names. If a zone does not implement
daylight saving time, the daylight saving time names should not be used.
If setZoneStrings has been called
on this DateFormatSymbols instance, then the strings
provided by that call are returned. Otherwise, the returned array
contains names provided by the Java runtime and by installed
TimeZoneNameProvider
implementations.
Sets time zone strings. The argument must be a
two-dimensional array of strings of size
n by
m,
where
m is at least 5. Each of the
n rows is an
entry containing the localized names for a single
TimeZone.
Each such row contains (with
i ranging from
0..
n-1):
zoneStrings[i][0] - time zone ID
zoneStrings[i][1] - long name of zone in standard
time
zoneStrings[i][2] - short name of zone in
standard time
zoneStrings[i][3] - long name of zone in daylight
saving time
zoneStrings[i][4] - short name of zone in daylight
saving time
The zone ID is
not localized; it's one of the valid IDs of
the
TimeZone class that are not
custom IDs.
All other entries are localized names.
for (int i = 0; i < newZoneStrings.length; ++i) { if (newZoneStrings[i].length < 5) { Gets localized date-time pattern characters. For example: 'u', 't', etc.
- Returns:
- the localized date-time pattern characters.
Sets localized date-time pattern characters. For example: 'u', 't', etc.
- Parameters:
newLocalPatternChars the new localized date-time
pattern characters.
Override hashCode.
Generates a hash code for the DateFormatSymbols object.
for (int index = 0; index < zoneStrings[0].length; ++index)
hashcode ^= zoneStrings[0][index].hashCode();
if (this == obj) return true;
&& that.localPatternChars == null)));
Useful constant for defining time zone offsets.
Cache to hold the FormatData and TimeZoneNames ResourceBundles
of a Locale.
Look up resource data for the desiredLocale in the cache; update the
cache if necessary.
for (i=0; i<lWeekdays.length; i++)
for (i=0; i<sWeekdays.length; i++)
Package private: used by SimpleDateFormat
Gets the index for the given time zone ID to obtain the time zone
strings for formatting. The time zone ID is just for programmatic
lookup. NOT LOCALIZED!!!
- Parameters:
ID the given time zone ID.- Returns:
- the index of the given time zone ID. Returns -1 if
the given time zone ID can't be located in the DateFormatSymbols object.
- See also:
java.util.SimpleTimeZone
for (int index=0; index<zoneStrings.length; index++)
Wrapper method to the getZoneStrings(), which is called from inside
the java.text package and not to mutate the returned arrays, so that
it does not need to create a defensive copy.
Clones an array of Strings.
- Parameters:
srcArray the source array to be cloned.count the number of elements in the given source array.- Returns:
- a cloned array.
System.arraycopy(srcArray, 0, dstArray, 0, srcArray.length);
Clones all the data members from the source DateFormatSymbols to
the target DateFormatSymbols. This is only for subclasses.
- Parameters:
src the source DateFormatSymbols.dst the target DateFormatSymbols.
dst.shortMonths = duplicate(src.shortMonths);
dst.shortWeekdays = duplicate(src.shortWeekdays);
if (src.zoneStrings != null) { if (dst.zoneStrings == null) { dst.zoneStrings = new String[src.zoneStrings.length][];
for (int i = 0; i < dst.zoneStrings.length; ++i) { dst.zoneStrings[i] = duplicate(src.zoneStrings[i]);
dst.localPatternChars = new String (src.localPatternChars);
Compares the equality of the two arrays of String.
- Parameters:
current this String array.other that String array.
int count = current.length;
for (int i = 0; i < count; ++i)
if (!current[i].equals(other[i]))
Write out the default serializable data, after ensuring the
zoneStrings field is initialized in order to make
sure the backward compatibility.
Obtains a DateFormatSymbols instance from a DateFormatSymbolsProvider
implementation.
assert params.length == 0;