DateFormatSymbols (Java SE 17 & JDK 17)
- All Implemented Interfaces:
Serializable,Cloneable
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.
SimpleDateFormat uses
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)).
If the locale contains "rg" (region override) Unicode extension, the symbols are overridden for the designated region.
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.
- Since:
- 1.1
- See Also:
-
Constructor Summary
Constructors
Construct a DateFormatSymbols object by loading format data from resources for the default
FORMATlocale.Construct a DateFormatSymbols object by loading format data from resources for the given locale.
-
Method Summary
clone()booleanReturns an array of all locales for which the
getInstancemethods of this class can return localized instances.getEras()Gets the
DateFormatSymbolsinstance for the default locale.Gets the
DateFormatSymbolsinstance for the specified locale.Gets localized date-time pattern characters.
Gets short month strings.
Gets short weekday strings.
inthashCode()voidvoidvoidsetLocalPatternChars(String newLocalPatternChars) Sets localized date-time pattern characters.
voidvoidSets short month strings.
voidSets short weekday strings.
voidvoidsetZoneStrings(String[][] newZoneStrings)
-
Constructor Details
-
DateFormatSymbols
public DateFormatSymbols()
Construct a DateFormatSymbols object by loading format data from resources for the default
FORMATlocale. This constructor can only construct instances for the locales supported by the Java runtime environment, not for those supported by installedDateFormatSymbolsProviderimplementations. For full locale coverage, use thegetInstancemethod.This is equivalent to calling
DateFormatSymbols(Locale.getDefault(Locale.Category.FORMAT)).- Throws:
MissingResourceException- if the resources for the default locale cannot be found or cannot be loaded.- See Also:
-
DateFormatSymbols
public DateFormatSymbols
(Locale locale) 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
DateFormatSymbolsProviderimplementations. For full locale coverage, use thegetInstancemethod.- Parameters:
locale- the desired locale- Throws:
MissingResourceException- if the resources for the specified locale cannot be found or cannot be loaded.- See Also:
-
-
Method Details
-
getAvailableLocales
public static Locale[] getAvailableLocales()
Returns an array of all locales for which the
getInstancemethods of this class can return localized instances. The returned array represents the union of locales supported by the Java runtime and by installedDateFormatSymbolsProviderimplementations. It must contain at least aLocaleinstance equal toLocale.US.- Returns:
- An array of locales for which localized
DateFormatSymbolsinstances are available. - Since:
- 1.6
-
getInstance
Gets the
DateFormatSymbolsinstance for the default locale. This method provides access toDateFormatSymbolsinstances for locales supported by the Java runtime itself as well as for those supported by installedDateFormatSymbolsProviderimplementations.This is equivalent to calling
getInstance(Locale.getDefault(Locale.Category.FORMAT)).- Returns:
- a
DateFormatSymbolsinstance. - Since:
- 1.6
- See Also:
-
getInstance
Gets the
DateFormatSymbolsinstance for the specified locale. This method provides access toDateFormatSymbolsinstances for locales supported by the Java runtime itself as well as for those supported by installedDateFormatSymbolsProviderimplementations.- Parameters:
locale- the given locale.- Returns:
- a
DateFormatSymbolsinstance. - Throws:
NullPointerException- iflocaleis null- Since:
- 1.6
-
getEras
public String[] getEras()
Gets era strings. For example: "AD" and "BC".
- Returns:
- the era strings.
-
setEras
public void setEras
(String[] newEras) Sets era strings. For example: "AD" and "BC".
- Parameters:
newEras- the new era strings.
-
getMonths
public String[] getMonths()
Gets month strings. For example: "January", "February", etc. An array with either 12 or 13 elements will be returned depending on whether or not
Calendar.UNDECIMBERis supported. UseCalendar.JANUARY,Calendar.FEBRUARY, etc. to index the result array.If the language requires different forms for formatting and stand-alone usages, this method returns month names in the formatting form. For example, the preferred month name for January in the Czech language is ledna in the formatting form, while it is leden in the stand-alone form. This method returns
"ledna"in this case. Refer to the Calendar Elements in the Unicode Locale Data Markup Language (LDML) specification for more details.- Implementation Requirements:
- This method returns 13 elements since
Calendar.UNDECIMBERis supported. - Returns:
- the month strings.
-
setMonths
public void setMonths
(String[] newMonths) Sets month strings. For example: "January", "February", etc.
- Parameters:
newMonths- the new month strings. The array should be indexed byCalendar.JANUARY,Calendar.FEBRUARY, etc.
-
getShortMonths
public String[] getShortMonths()
Gets short month strings. For example: "Jan", "Feb", etc. An array with either 12 or 13 elements will be returned depending on whether or not
Calendar.UNDECIMBERis supported. UseCalendar.JANUARY,Calendar.FEBRUARY, etc. to index the result array.If the language requires different forms for formatting and stand-alone usages, this method returns short month names in the formatting form. For example, the preferred abbreviation for January in the Catalan language is de gen. in the formatting form, while it is gen. in the stand-alone form. This method returns
"de gen."in this case. Refer to the Calendar Elements in the Unicode Locale Data Markup Language (LDML) specification for more details.- Implementation Requirements:
- This method returns 13 elements since
Calendar.UNDECIMBERis supported. - Returns:
- the short month strings.
-
setShortMonths
public void setShortMonths
(String[] newShortMonths) Sets short month strings. For example: "Jan", "Feb", etc.
- Parameters:
newShortMonths- the new short month strings. The array should be indexed byCalendar.JANUARY,Calendar.FEBRUARY, etc.
-
getWeekdays
public String[] getWeekdays()
Gets weekday strings. For example: "Sunday", "Monday", etc.
- Returns:
- the weekday strings. Use
Calendar.SUNDAY,Calendar.MONDAY, etc. to index the result array.
-
setWeekdays
public void setWeekdays
(String[] newWeekdays) Sets weekday strings. For example: "Sunday", "Monday", etc.
- Parameters:
newWeekdays- the new weekday strings. The array should be indexed byCalendar.SUNDAY,Calendar.MONDAY, etc.
-
getShortWeekdays
public String[] getShortWeekdays()
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.
-
setShortWeekdays
public void setShortWeekdays
(String[] newShortWeekdays) Sets short weekday strings. For example: "Sun", "Mon", etc.
- Parameters:
newShortWeekdays- the new short weekday strings. The array should be indexed byCalendar.SUNDAY,Calendar.MONDAY, etc.
-
getAmPmStrings
public String[] getAmPmStrings()
Gets ampm strings. For example: "AM" and "PM".
- Returns:
- the ampm strings.
-
setAmPmStrings
public void setAmPmStrings
(String[] newAmpms) Sets ampm strings. For example: "AM" and "PM".
- Parameters:
newAmpms- the new ampm strings.
-
getZoneStrings
public String[][] getZoneStrings()
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 (withiranging from 0..n-1):zoneStrings[i][0]- time zone IDzoneStrings[i][1]- long name of zone in standard timezoneStrings[i][2]- short name of zone in standard timezoneStrings[i][3]- long name of zone in daylight saving timezoneStrings[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
TimeZoneclass 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
setZoneStringshas been called on thisDateFormatSymbolsinstance, then the strings provided by that call are returned. Otherwise, the returned array contains names provided by the Java runtime and by installedTimeZoneNameProviderimplementations.- Returns:
- the time zone strings.
- See Also:
-
setZoneStrings
public void setZoneStrings
(String[][] newZoneStrings) 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 (withiranging from 0..n-1):zoneStrings[i][0]- time zone IDzoneStrings[i][1]- long name of zone in standard timezoneStrings[i][2]- short name of zone in standard timezoneStrings[i][3]- long name of zone in daylight saving timezoneStrings[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
TimeZoneclass that are not custom IDs. All other entries are localized names.- Parameters:
newZoneStrings- the new time zone strings.- Throws:
IllegalArgumentException- if the length of any row innewZoneStringsis less than 5NullPointerException- ifnewZoneStringsis null- See Also:
-
getLocalPatternChars
public String getLocalPatternChars()
Gets localized date-time pattern characters. For example: 'u', 't', etc.
- Returns:
- the localized date-time pattern characters.
-
setLocalPatternChars
public void setLocalPatternChars
(String newLocalPatternChars) Sets localized date-time pattern characters. For example: 'u', 't', etc.
- Parameters:
newLocalPatternChars- the new localized date-time pattern characters.
-
clone
Overrides Cloneable
-
hashCode
public int hashCode()
Override hashCode. Generates a hash code for the DateFormatSymbols object.
-
equals
public boolean equals
(Object obj) Override equals
-