public class DateFormatSymbols
extends Object implements Serializable, Cloneable
| java.lang.Object | |
| java.text.DateFormatSymbols | |
DateFormatSymbols是封装可本地化的日期时间格式数据的公共类,例如月份名称,星期几名称和时区数据。 DateFormat和SimpleDateFormat都使用DateFormatSymbols来封装这些信息。
通常你不应该直接使用DateFormatSymbols 。 相反,我们鼓励你创建一个日期-时间格式化DateFormat类的工厂方法: getTimeInstance , getDateInstance ,或getDateTimeInstance 。 这些方法自动为格式化程序创建一个DateFormatSymbols ,以便您不必这样做。 格式化程序创建后,您可以使用setPattern方法修改其格式模式。 有关使用DateFormat的工厂方法创建格式化程序的更多信息,请参阅DateFormat 。
如果您决定为特定区域创建具有特定格式模式的日期 - 时间格式化程序,则可以这样做:
new SimpleDateFormat(aPattern, DateFormatSymbols.getInstance(aLocale)).
DateFormatSymbols对象是可复制的。 当您获得DateFormatSymbols对象时,请随时修改日期时间格式数据。 例如,您可以将本地化的日期时间格式模式字符替换为您感觉易于记忆的字符。 或者,您可以将代表性城市更改为您最喜欢的城市。
可以添加新的 DateFormatSymbols子类以支持 SimpleDateFormat以便日期时间格式化其他语言环境。
Public constructors |
|
|---|---|
DateFormatSymbols() 通过从默认语言环境的资源中加载格式数据构建DateFormatSymbols对象。 |
|
DateFormatSymbols(Locale locale) 通过从给定语言环境的资源加载格式数据构造一个DateFormatSymbols对象。 |
|
公共方法(Public methods) |
|
|---|---|
Object |
clone() 覆盖可复制 |
boolean |
equals(Object obj) 覆盖等于 |
String[] |
getAmPmStrings() 获取ampm字符串。 |
static Locale[] |
getAvailableLocales() 返回 |
String[] |
getEras() 获取时代字符串。 |
static final DateFormatSymbols |
getInstance() 获取默认语言环境的 |
static final DateFormatSymbols |
getInstance(Locale locale) 获取指定语言环境的 |
String |
getLocalPatternChars() 获取本地化的日期时间模式字符。 |
String[] |
getMonths() 获取月份字符串。 |
String[] |
getShortMonths() 获取较短的月份字符串。 |
String[] |
getShortWeekdays() 得到短的周日字符串。 |
String[] |
getWeekdays() 获取星期几字符串。 |
String[][] |
getZoneStrings() 获取时区字符串。 |
int |
hashCode() 覆盖hashCode。 |
void |
setAmPmStrings(String[] newAmpms) 设置ampm字符串。 |
void |
setEras(String[] newEras) 设置时代字符串。 |
void |
setLocalPatternChars(String newLocalPatternChars) 设置本地化的日期时间模式字符。 |
void |
setMonths(String[] newMonths) 设置月份字符串。 |
void |
setShortMonths(String[] newShortMonths) 设置短月份字符串。 |
void |
setShortWeekdays(String[] newShortWeekdays) 设置简短的周日字符串。 |
void |
setWeekdays(String[] newWeekdays) 设置星期几字符串。 |
void |
setZoneStrings(String[][] newZoneStrings) 设置时区字符串。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
DateFormatSymbols ()
通过从默认语言环境的资源中加载格式数据构建DateFormatSymbols对象。 此构造函数只能为Java运行时环境支持的语言环境构建实例,而不能为已安装的DateFormatSymbolsProvider实现支持的语言环境构建实例。 要获得完整的区域覆盖范围,请使用getInstance方法。
| 抛出异常(Throws) | |
|---|---|
MissingResourceException |
if the resources for the default locale cannot be found or cannot be loaded. |
也可以看看:
DateFormatSymbols (Locale locale)
通过从给定语言环境的资源加载格式数据构造一个DateFormatSymbols对象。 此构造函数只能为Java运行时环境支持的语言环境构建实例,而不能为已安装的DateFormatSymbolsProvider实现支持的语言环境构建实例。 要获得完整的区域覆盖,请使用getInstance方法。
| 参数(Parameters) | |
|---|---|
locale |
Locale
|
| 抛出异常(Throws) | |
|---|---|
MissingResourceException |
if the resources for the specified locale cannot be found or cannot be loaded. |
也可以看看:
boolean equals (Object obj)
覆盖等于
| 参数(Parameters) | |
|---|---|
obj |
Object: the reference object with which to compare. |
| 返回(Returns) | |
|---|---|
boolean |
true if this object is the same as the obj argument; false otherwise. |
String[] getAmPmStrings ()
获取ampm字符串。 例如:“AM”和“PM”。
| 返回(Returns) | |
|---|---|
String[] |
the ampm strings. |
Locale[] getAvailableLocales ()
返回getInstance方法可返回本地化实例的所有语言环境的数组。 返回的数组表示Java运行时支持的语言环境联合以及安装的DateFormatSymbolsProvider实现。 它必须包含至少一个等于Locale.US的Locale实例。
| 返回(Returns) | |
|---|---|
Locale[] |
An array of locales for which localized DateFormatSymbols instances are available. |
String[] getEras ()
获取时代字符串。 例如:“AD”和“BC”。
| 返回(Returns) | |
|---|---|
String[] |
the era strings. |
DateFormatSymbols getInstance ()
获取默认语言环境的DateFormatSymbols实例。 此方法提供对Java运行时自身支持的语言环境以及已安装的DateFormatSymbolsProvider实现支持的语言环境的DateFormatSymbols实例的访问。
| 返回(Returns) | |
|---|---|
DateFormatSymbols |
a DateFormatSymbols instance. |
DateFormatSymbols getInstance (Locale locale)
获取指定语言环境的DateFormatSymbols实例。 此方法提供对Java运行时本身支持的语言环境以及已安装的DateFormatSymbolsProvider实现支持的语言环境的DateFormatSymbols实例的访问。
| 参数(Parameters) | |
|---|---|
locale |
Locale: the given locale. |
| 返回(Returns) | |
|---|---|
DateFormatSymbols |
a DateFormatSymbols instance. |
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
if locale is null |
String getLocalPatternChars ()
获取本地化的日期时间模式字符。 例如:'u','t'等。
| 返回(Returns) | |
|---|---|
String |
the localized date-time pattern characters. |
String[] getMonths ()
获取月份字符串。 例如:“一月”,“二月”等。
| 返回(Returns) | |
|---|---|
String[] |
the month strings. |
String[] getShortMonths ()
获取较短的月份字符串。 例如:“Jan”,“Feb”等。
| 返回(Returns) | |
|---|---|
String[] |
the short month strings. |
String[] getShortWeekdays ()
得到短的周日字符串。 例如:“太阳”,“星期一”等。
| 返回(Returns) | |
|---|---|
String[] |
the short weekday strings. Use Calendar.SUNDAY, Calendar.MONDAY, etc. to index the result array. |
String[] getWeekdays ()
获取星期几字符串。 例如:“星期天”,“星期一”等。
| 返回(Returns) | |
|---|---|
String[] |
the weekday strings. Use Calendar.SUNDAY, Calendar.MONDAY, etc. to index the result array. |
String[][] getZoneStrings ()
获取时区字符串。 不鼓励使用这种方法; 改为使用TimeZone.getDisplayName() 。
返回的值是大小为n乘m的字符串的二维数组,其中m至少为5. n行中的每一行都是包含单个TimeZone的本地化名称的条目。 每个这样的行包含(具有范围从0 ... n -1的i ):
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 timeTimeZone 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.
如果setZoneStrings一直呼吁这个DateFormatSymbols实例,然后通过调用提供的字符串返回。 否则,返回的数组包含由Java运行时和安装的TimeZoneNameProvider实现提供的名称。
| 返回(Returns) | |
|---|---|
String[][] |
the time zone strings. |
也可以看看:
int hashCode ()
覆盖hashCode。 为DateFormatSymbols对象生成一个哈希码。
| 返回(Returns) | |
|---|---|
int |
a hash code value for this object. |
void setAmPmStrings (String[] newAmpms)
设置ampm字符串。 例如:“AM”和“PM”。
| 参数(Parameters) | |
|---|---|
newAmpms |
String: the new ampm strings. |
void setEras (String[] newEras)
设置时代字符串。 例如:“AD”和“BC”。
| 参数(Parameters) | |
|---|---|
newEras |
String: the new era strings. |
void setLocalPatternChars (String newLocalPatternChars)
设置本地化的日期时间模式字符。 例如:'u','t'等。
| 参数(Parameters) | |
|---|---|
newLocalPatternChars |
String: the new localized date-time pattern characters. |
void setMonths (String[] newMonths)
设置月份字符串。 例如:“一月”,“二月”等。
| 参数(Parameters) | |
|---|---|
newMonths |
String: the new month strings. |
void setShortMonths (String[] newShortMonths)
设置短月份字符串。 例如:“Jan”,“Feb”等。
| 参数(Parameters) | |
|---|---|
newShortMonths |
String: the new short month strings. |
void setShortWeekdays (String[] newShortWeekdays)
设置简短的周日字符串。 例如:“太阳”,“星期一”等。
| 参数(Parameters) | |
|---|---|
newShortWeekdays |
String: the new short weekday strings. The array should be indexed by Calendar.SUNDAY, Calendar.MONDAY, etc. |
void setWeekdays (String[] newWeekdays)
设置星期几字符串。 例如:“星期天”,“星期一”等。
| 参数(Parameters) | |
|---|---|
newWeekdays |
String: the new weekday strings. The array should be indexed by Calendar.SUNDAY, Calendar.MONDAY, etc. |
void setZoneStrings (String[][] newZoneStrings)
设置时区字符串。 参数必须是大小为n乘m的字符串的二维数组,其中m至少为5. n行中的每一行都是包含单个TimeZone的本地化名称的条目。 每个这样的行包含(具有范围从0 ... n -1的i ):
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 timeTimeZone class that are not
custom IDs. All other entries are localized names.
| 参数(Parameters) | |
|---|---|
newZoneStrings |
String: the new time zone strings. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
if the length of any row in newZoneStrings is less than 5 |
NullPointerException |
if newZoneStrings is null |
也可以看看: