public class SimpleDateFormat
extends DateFormat
java.lang.Object | ||||
↳ | java.text.Format | |||
↳ | android.icu.text.UFormat | |||
↳ | android.icu.text.DateFormat | |||
↳ | android.icu.text.SimpleDateFormat |
[icu增强] ICU的替代SimpleDateFormat
。 ICU特有的方法,字段和其他功能标记为“ [icu] ”。
SimpleDateFormat
是以区分语言环境的方式格式化和解析日期的具体类。 它允许格式化(日期 - >文本),解析(文本 - >日期)和规范化。
SimpleDateFormat
允许您从选择任何用户定义的日期时间格式模式开始。 但是,鼓励您使用getTimeInstance
中的getDateInstance
或getDateTimeInstance
创建日期 - 时间格式DateFormat
。 这些类方法中的每一个都可以返回使用默认格式模式初始化的日期/时间格式化程序。 您可以根据需要使用applyPattern
方法修改格式模式。 有关使用这些方法的更多信息,请参阅DateFormat
。
日期和时间模式:
日期和时间格式由日期和时间模式字符串指定。 在日期和时间模式字符串中,所有未加引号的ASCII字母[A-Za-z]保留为表示日历字段的模式字母。 SimpleDateFormat
支持UTS#35 Unicode Locale Data Markup Language (LDML)定义的日期和时间格式化算法和模式字母。 以下模式字母当前可用(请注意,实际值取决于CLDR,可能会从此处显示的示例中更改):
Field Sym. No. Example 描述 era G 1..3 AD Era - Replaced with the Era string for the current date. One to three letters for the abbreviated form, four letters for the long (wide) form, five for the narrow form. 4 Anno Domini 5 A year y 1..n 1996 Year. Normally the length specifies the padding, but for two letters it also specifies the maximum length. Example:
Year y yy yyy yyyy yyyyy AD 1 1 01 001 0001 00001 AD 12 12 12 012 0012 00012 AD 123 123 23 123 0123 00123 AD 1234 1234 34 1234 1234 01234 AD 12345 12345 45 12345 12345 12345 Y 1..n 1997 Year (in "Week of Year" based calendars). Normally the length specifies the padding, but for two letters it also specifies the maximum length. This year designation is used in ISO year-week calendar as defined by ISO 8601, but can be used in non-Gregorian based calendar systems where week date processing is desired. May not always be the same value as calendar year. u 1..n 4601 Extended year. This is a single number designating the year of this calendar system, encompassing all supra-year fields. For example, for the Julian calendar system, year numbers are positive, with an era of BCE or CE. An extended year value for the Julian calendar system assigns positive values to CE years and negative values to BCE years, with 1 BCE being year 0. U 1..3 甲子 Cyclic year name. Calendars such as the Chinese lunar calendar (and related calendars) and the Hindu calendars use 60-year cycles of year names. Use one through three letters for the abbreviated name, four for the full (wide) name, or five for the narrow name (currently the data only provides abbreviated names, which will be used for all requested name widths). If the calendar does not provide cyclic year name data, or if the year value to be formatted is out of the range of years for which cyclic name data is provided, then numeric formatting is used (behaves like 'y'). 4 (currently also 甲子) 5 (currently also 甲子) quarter Q 1..2 02 Quarter - Use one or two for the numerical quarter, three for the abbreviation, or four for the full (wide) name (five for the narrow name is not yet supported). 3 Q2 4 2nd quarter q 1..2 02 Stand-Alone Quarter - Use one or two for the numerical quarter, three for the abbreviation, or four for the full name (five for the narrow name is not yet supported). 3 Q2 4 2nd quarter month M 1..2 09 Month - Use one or two for the numerical month, three for the abbreviation, four for the full (wide) name, or five for the narrow name. With two ("MM"), the month number is zero-padded if necessary (e.g. "08"). 3 Sep 4 September 5 S L 1..2 09 Stand-Alone Month - Use one or two for the numerical month, three for the abbreviation, four for the full (wide) name, or 5 for the narrow name. With two ("LL"), the month number is zero-padded if necessary (e.g. "08"). 3 Sep 4 September 5 S week w 1..2 27 Week of Year. Use "w" to show the minimum number of digits, or "ww" to always show two digits (zero-padding if necessary, e.g. "08"). W 1 3 Week of Month day d 1..2 1 Date - Day of the month. Use "d" to show the minimum number of digits, or "dd" to always show two digits (zero-padding if necessary, e.g. "08"). D 1..3 345 Day of year F 1 2 Day of Week in Month. The example is for the 2nd Wed in July g 1..n 2451334 Modified Julian day. This is different from the conventional Julian day number in two regards. First, it demarcates days at local zone midnight, rather than noon GMT. Second, it is a local number; that is, it depends on the local time zone. It can be thought of as a single number that encompasses all the date-related fields. week
dayE 1..3 Tue Day of week - Use one through three letters for the short day, four for the full (wide) name, five for the narrow name, or six for the short name. 4 Tuesday 5 T 6 Tu e 1..2 2 Local day of week. Same as E except adds a numeric value that will depend on the local starting day of the week, using one or two letters. For this example, Monday is the first day of the week. 3 Tue 4 Tuesday 5 T 6 Tu c 1 2 Stand-Alone local day of week - Use one letter for the local numeric value (same as 'e'), three for the short day, four for the full (wide) name, five for the narrow name, or six for the short name. 3 Tue 4 Tuesday 5 T 6 Tu period a 1 AM AM or PM hour h 1..2 11 Hour [1-12]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern generation, it should match the 12-hour-cycle format preferred by the locale (h or K); it should not match a 24-hour-cycle format (H or k). Use hh for zero padding. H 1..2 13 Hour [0-23]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern generation, it should match the 24-hour-cycle format preferred by the locale (H or k); it should not match a 12-hour-cycle format (h or K). Use HH for zero padding. K 1..2 0 Hour [0-11]. When used in a skeleton, only matches K or h, see above. Use KK for zero padding. k 1..2 24 Hour [1-24]. When used in a skeleton, only matches k or H, see above. Use kk for zero padding. minute m 1..2 59 Minute. Use "m" to show the minimum number of digits, or "mm" to always show two digits (zero-padding if necessary, e.g. "08").. second s 1..2 12 Second. Use "s" to show the minimum number of digits, or "ss" to always show two digits (zero-padding if necessary, e.g. "08"). S 1..n 3450 Fractional Second - truncates (like other time fields) to the count of letters when formatting. Appends zeros if more than 3 letters specified. Truncates at three significant digits when parsing. (example shows display using pattern SSSS for seconds value 12.34567) A 1..n 69540000 Milliseconds in day. This field behaves exactly like a composite of all time-related fields, not including the zone fields. As such, it also reflects discontinuities of those fields on DST transition days. On a day of DST onset, it will jump forward. On a day of DST cessation, it will jump backward. This reflects the fact that is must be combined with the offset field to obtain a unique local time value. zone z 1..3 PDT The short specific non-location format. Where that is unavailable, falls back to the short localized GMT format ("O"). 4 Pacific Daylight Time The long specific non-location format. Where that is unavailable, falls back to the long localized GMT format ("OOOO"). Z 1..3 -0800 The ISO8601 basic format with hours, minutes and optional seconds fields. The format is equivalent to RFC 822 zone format (when optional seconds field is absent). This is equivalent to the "xxxx" specifier. 4 GMT-8:00 The long localized GMT format. This is equivalent to the "OOOO" specifier. 5 -08:00
-07:52:58The ISO8601 extended format with hours, minutes and optional seconds fields. The ISO8601 UTC indicator "Z" is used when local time offset is 0. This is equivalent to the "XXXXX" specifier. O 1 GMT-8 The short localized GMT format. 4 GMT-08:00 The long localized GMT format. v 1 PT The short generic non-location format. Where that is unavailable, falls back to the generic location format ("VVVV"), then the short localized GMT format as the final fallback. 4 Pacific Time The long generic non-location format. Where that is unavailable, falls back to generic location format ("VVVV"). V 1 uslax The short time zone ID. Where that is unavailable, the special short time zone ID unk (Unknown Zone) is used.
Note: This specifier was originally used for a variant of the short specific non-location format, but it was deprecated in the later version of the LDML specification. In CLDR 23/ICU 51, the definition of the specifier was changed to designate a short time zone ID.2 America/Los_Angeles The long time zone ID. 3 Los Angeles The exemplar city (location) for the time zone. Where that is unavailable, the localized exemplar city name for the special zone Etc/Unknown is used as the fallback (for example, "Unknown City"). 4 Los Angeles Time The generic location format. Where that is unavailable, falls back to the long localized GMT format ("OOOO"; Note: Fallback is only necessary with a GMT-style Time Zone ID, like Etc/GMT-830.)
This is especially useful when presenting possible timezone choices for user selection, since the naming is more uniform than the "v" format.X 1 -08
+0530
ZThe ISO8601 basic format with hours field and optional minutes field. The ISO8601 UTC indicator "Z" is used when local time offset is 0. 2 -0800
ZThe ISO8601 basic format with hours and minutes fields. The ISO8601 UTC indicator "Z" is used when local time offset is 0. 3 -08:00
ZThe ISO8601 extended format with hours and minutes fields. The ISO8601 UTC indicator "Z" is used when local time offset is 0. 4 -0800
-075258
ZThe ISO8601 basic format with hours, minutes and optional seconds fields. (Note: The seconds field is not supported by the ISO8601 specification.) The ISO8601 UTC indicator "Z" is used when local time offset is 0. 5 -08:00
-07:52:58
ZThe ISO8601 extended format with hours, minutes and optional seconds fields. (Note: The seconds field is not supported by the ISO8601 specification.) The ISO8601 UTC indicator "Z" is used when local time offset is 0. x 1 -08
+0530The ISO8601 basic format with hours field and optional minutes field. 2 -0800 The ISO8601 basic format with hours and minutes fields. 3 -08:00 The ISO8601 extended format with hours and minutes fields. 4 -0800
-075258The ISO8601 basic format with hours, minutes and optional seconds fields. (Note: The seconds field is not supported by the ISO8601 specification.) 5 -08:00
-07:52:58The ISO8601 extended format with hours, minutes and optional seconds fields. (Note: The seconds field is not supported by the ISO8601 specification.)
模式中不在['a'..'z']和['A'..'Z']范围内的任何字符将被视为带引号的文本。 例如,':','。','','#'和'@'等字符将出现在结果时间文本中,即使它们不包含在单引号内。
包含任何无效模式字母的模式在格式化或解析过程中将导致引发异常。
使用美国语言环境的示例:
Code Sample:Format Pattern Result -------------- ------- "yyyy.MM.dd G 'at' HH:mm:ss vvvv" ->> 1996.07.10 AD at 15:08:56 Pacific Time "EEE, MMM d, ''yy" ->> Wed, July 10, '96 "h:mm a" ->> 12:08 PM "hh 'o''clock' a, zzzz" ->> 12 o'clock PM, Pacific Daylight Time "K:mm a, vvv" ->> 0:00 PM, PT "yyyyy.MMMMM.dd GGG hh:mm aaa" ->> 01996.July.10 AD 12:08 PM
In the example, the time valueSimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "PST"); pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2*60*60*1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*60*60*1000);
// Format the current time. SimpleDateFormat formatter = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss a zzz"); Date currentTime_1 = new Date(); String dateString = formatter.format(currentTime_1);
// Parse the previous string back into a Date. ParsePosition pos = new ParsePosition(0); Date currentTime_2 = formatter.parse(dateString, pos);
currentTime_2
obtained from parsing will be equal to
currentTime_1
. However, they may not be equal if the am/pm marker 'a' is left out from the format pattern while the "hour in am/pm" pattern symbol is used. This information loss can happen when formatting the time in PM.
使用缩写年份模式(“yy”)解析日期字符串时,SimpleDateFormat必须解释相对于某个世纪的缩写年份。 它通过将日期调整为在创建SimpleDateFormat实例之前的80年之内和20年之后执行此操作。 例如,使用1997年1月1日创建的“MM / dd / yy”模式和SimpleDateFormat实例,字符串“01/11/12”将被解释为2012年1月11日,而字符串“05/04 / 64“将被解释为1964年5月4日。在解析期间,只有由isDigit(int)
定义的由两个数字组成的字符串将被解析为默认世纪。 任何其他数字字符串(例如一个数字字符串,三个或更多数字字符串或不是全部数字的两位数字符串(例如“-1”))都按字面解释。 因此,“01/02/3”或“01/02/003”的解析方式与公元1月2日相同。 同样,“01/02 / -3”被解析为公元前4年1月2日。
如果年份模式不具有两个'y'字符,则无论数字的位数如何,都会逐字解释年份。 因此,使用“MM / dd / yyyy”模式,“01/11/12”分析到公元12年1月11日
当数字字段直接相互邻接时,没有中间分隔字符,它们构成一系列邻接的数字字段。 这些运行特别被解析。 例如,格式“HHmmss”将输入文本“123456”解析为12:34:56,将输入文本“12345”解析为1:23:45,并且无法解析“1234”。 换句话说,运行的最左边的字段是灵活的,而其他字段保持固定的宽度。 如果解析在运行的任何地方失败,则最左边的字段缩短一个字符,并且整个运行再次被解析。 重复此操作直至解析成功或最左边的字段长度为一个字符。 如果解析仍然失败,那么运行的解析失败。
对于没有名称的时区,请使用字符串GMT +小时:分钟或GMT-hours:分钟。
日历定义了一周中的第一天,一年中的第一周,小时是否为零(0 vs 12或24)以及时区。 有一个通用的十进制格式来处理所有的数字; 数字计数根据模式以编程方式处理。
也可以看看:
Inherited constants |
---|
From class android.icu.text.DateFormat
|
Inherited fields |
---|
From class android.icu.text.DateFormat
|
Public constructors |
|
---|---|
SimpleDateFormat() 使用默认的 |
|
SimpleDateFormat(String pattern) 使用默认的 |
|
SimpleDateFormat(String pattern, Locale loc) 使用给定的模式和区域设置构造一个SimpleDateFormat。 |
|
SimpleDateFormat(String pattern, ULocale loc) 使用给定的模式和区域设置构造一个SimpleDateFormat。 |
|
SimpleDateFormat(String pattern, String override, ULocale loc) 使用给定的模式,覆盖和区域设置构造一个SimpleDateFormat。 |
|
SimpleDateFormat(String pattern, DateFormatSymbols formatData) 使用给定的模式和特定于语言环境的符号数据构造SimpleDateFormat。 |
Public methods |
|
---|---|
void |
applyLocalizedPattern(String pat) 将给定的本地化模式字符串应用于此日期格式。 |
void |
applyPattern(String pat) 将给定的未本地化模式字符串应用于此日期格式。 |
Object |
clone() 覆盖可复制 |
boolean |
equals(Object obj) 覆盖等于。 |
StringBuffer |
format(Calendar cal, StringBuffer toAppendTo, FieldPosition pos) 格式化日期或时间,这是自1970年1月1日,格林威治标准时间00:00:00以来的标准毫秒数。 |
AttributedCharacterIterator |
formatToCharacterIterator(Object obj) 将对象格式化为属性字符串,并返回相应的迭代器覆盖超类方法。 |
Date |
get2DigitYearStart() 返回100年期间的两位数年份的开始日期被解释为在之内。 |
DateFormatSymbols |
getDateFormatSymbols() 获取日期/时间格式数据。 |
NumberFormat |
getNumberFormat(char field) 给出字段使用的NumberFormat,如'y'(年)和'M'(年) |
TimeZoneFormat |
getTimeZoneFormat() [icu]获取此日期/时间格式化程序用于格式化和分析时区的时区格式器。 |
int |
hashCode() 覆盖hashCode。 |
void |
parse(String text, Calendar cal, ParsePosition parsePos) 重写DateFormat |
void |
set2DigitYearStart(Date startDate) 设置100年期间的两位数年份将被解释为在用户指定的日期开始。 |
void |
setContext(DisplayContext context) [icu]在格式化程序中设置特定的DisplayContext值,例如CAPITALIZATION_FOR_STANDALONE。 |
void |
setDateFormatSymbols(DateFormatSymbols newFormatSymbols) 允许您设置日期/时间格式数据。 |
void |
setNumberFormat(String fields, NumberFormat overrideNF) 允许用户为多个字段设置NumberFormat它可以是单个字段,如:“y”(年)或“M”(月)可以将多个字段组合在一起:“yMd”(年,月和日)注:1符号字段对于多个符号字段是足够的(所以“y”将覆盖“yy”,“yyy”)如果字段不是数字,则覆盖没有效果(如“MMM”将使用缩写,而不是数字字段) |
void |
setNumberFormat(NumberFormat newNumberFormat) 覆盖超类方法,并且此方法还会清除之前由 |
void |
setTimeZoneFormat(TimeZoneFormat tzfmt) [icu]允许您设置时区格式化程序。 |
String |
toLocalizedPattern() 返回描述此日期格式的本地化模式字符串。 |
String |
toPattern() 返回描述此日期格式的模式字符串。 |
Protected methods |
|
---|---|
DateFormatSymbols |
getSymbols() 子类访问DateFormatSymbols的方法。 |
int |
matchQuarterString(String text, int start, int field, String[] data, Calendar cal) 尝试将给定位置上的文本与季度字符串数组进行匹配。 |
int |
matchString(String text, int start, int field, String[] data, Calendar cal) 尝试将给定位置上的文本与字符串数组进行匹配。 |
DateFormat.Field |
patternCharToDateFormatField(char ch) 返回与指定格式模式字符关联的DateFormat.Field常量。 |
String |
subFormat(char ch, int count, int beginOffset, FieldPosition pos, DateFormatSymbols fmtData, Calendar cal) 根据模式字符格式化单个字段。 |
int |
subParse(String text, int start, char ch, int count, boolean obeyCount, boolean allowNegative, boolean[] ambiguousYear, Calendar cal) 受保护的方法,将输入字符串的一个字段转换为 |
String |
zeroPaddingNumber(long value, int minDigits, int maxDigits) 使用指定的最小和最大位数格式化数字。 |
Inherited methods |
|
---|---|
From class android.icu.text.DateFormat
|
|
From class java.text.Format
|
|
From class java.lang.Object
|
SimpleDateFormat ()
使用默认的FORMAT
语言环境的默认模式构造SimpleDateFormat。 注意:并非所有语言环境都支持SimpleDateFormat; 为了完整性,请使用DateFormat类中的工厂方法。
也可以看看:
SimpleDateFormat (String pattern)
使用默认的FORMAT
语言环境中的给定模式构造SimpleDateFormat。 注意:并非所有语言环境都支持SimpleDateFormat; 为了完整性,请使用DateFormat类中的工厂方法。
Parameters | |
---|---|
pattern |
String
|
也可以看看:
SimpleDateFormat (String pattern, Locale loc)
使用给定的模式和区域设置构造一个SimpleDateFormat。 注意:并非所有语言环境都支持SimpleDateFormat; 为了完整性,请使用DateFormat类中的工厂方法。
Parameters | |
---|---|
pattern |
String
|
loc |
Locale
|
SimpleDateFormat (String pattern, ULocale loc)
使用给定的模式和区域设置构造一个SimpleDateFormat。 注意:并非所有语言环境都支持SimpleDateFormat; 为了完整性,请使用DateFormat类中的工厂方法。
Parameters | |
---|---|
pattern |
String
|
loc |
ULocale
|
SimpleDateFormat (String pattern, String override, ULocale loc)
使用给定的模式,覆盖和区域设置构造一个SimpleDateFormat。
Parameters | |
---|---|
pattern |
String : The pattern to be used |
override |
String : The override string. A numbering system override string can take one of the following forms: 1). If just a numbering system name is specified, it applies to all numeric fields in the date format pattern. 2). To specify an alternate numbering system on a field by field basis, use the field letters from the pattern followed by an = sign, followed by the numbering system name. For example, to specify that just the year be formatted using Hebrew digits, use the override "y=hebr". Multiple overrides can be specified in a single string by separating them with a semi-colon. For example, the override string "m=thai;y=deva" would format using Thai digits for the month and Devanagari digits for the year. |
loc |
ULocale : The locale to be used |
SimpleDateFormat (String pattern, DateFormatSymbols formatData)
使用给定的模式和特定于语言环境的符号数据构造SimpleDateFormat。 警告:使用数字的默认FORMAT
区域设置!
Parameters | |
---|---|
pattern |
String
|
formatData |
DateFormatSymbols
|
void applyLocalizedPattern (String pat)
将给定的本地化模式字符串应用于此日期格式。
Parameters | |
---|---|
pat |
String
|
void applyPattern (String pat)
将给定的未本地化模式字符串应用于此日期格式。
Parameters | |
---|---|
pat |
String
|
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. |
StringBuffer format (Calendar cal, StringBuffer toAppendTo, FieldPosition pos)
格式化日期或时间,这是自1970年1月1日,格林威治标准时间00:00:00以来的标准毫秒数。
示例:使用美国语言环境:“HH:mm:ss zzz”处的“yyyy.MM.dd G” - >> 1996.07.10 AD at 15:08:56 PDT
Parameters | |
---|---|
cal |
Calendar : the calendar whose date-time value is to be formatted into a date-time string |
toAppendTo |
StringBuffer : where the new date-time text is to be appended |
pos |
FieldPosition : the formatting position. On input: an alignment field, if desired. On output: the offsets of the alignment field. |
Returns | |
---|---|
StringBuffer |
the formatted date-time string. |
也可以看看:
AttributedCharacterIterator formatToCharacterIterator (Object obj)
将对象格式化为属性字符串,并返回相应的迭代器覆盖超类方法。
Parameters | |
---|---|
obj |
Object : The object to format |
Returns | |
---|---|
AttributedCharacterIterator |
AttributedCharacterIterator describing the formatted value. |
Date get2DigitYearStart ()
返回100年期间的两位数年份的开始日期被解释为在之内。
Returns | |
---|---|
Date |
the start of the 100-year period into which two digit years are parsed |
DateFormatSymbols getDateFormatSymbols ()
获取日期/时间格式数据。
Returns | |
---|---|
DateFormatSymbols |
a copy of the date-time formatting data associated with this date-time formatter. |
NumberFormat getNumberFormat (char field)
给出字段使用的NumberFormat,如'y'(年)和'M'(年)
Parameters | |
---|---|
field |
char : the field the user wants |
Returns | |
---|---|
NumberFormat |
override NumberFormat used for the field |
TimeZoneFormat getTimeZoneFormat ()
[icu]获取此日期/时间格式化程序用于格式化和分析时区的时区格式器。
Returns | |
---|---|
TimeZoneFormat |
the time zone formatter which this date/time formatter uses. |
int hashCode ()
覆盖hashCode。 生成SimpleDateFormat对象的哈希码
Returns | |
---|---|
int |
a hash code value for this object. |
void parse (String text, Calendar cal, ParsePosition parsePos)
重写DateFormat
Parameters | |
---|---|
text |
String : The date/time string to be parsed |
cal |
Calendar : The calendar set on input to the date and time to be used for missing values in the date/time string being parsed, and set on output to the parsed date/time. In general, this should be initialized before calling this method - either cleared or set to the current date, depending on desired behavior. If this parse fails, the calendar may still have been modified. When the calendar type is different from the internal calendar held by this DateFormat instance, calendar field values will be parsed based on the internal calendar initialized with the time and the time zone taken from this calendar, then the parse result (time in milliseconds and time zone) will be set back to this calendar. |
parsePos |
ParsePosition : On input, the position at which to start parsing; on output, the position at which parsing terminated, or the start position if the parse failed. |
也可以看看:
void set2DigitYearStart (Date startDate)
设置100年期间的两位数年份将被解释为在用户指定的日期开始。
Parameters | |
---|---|
startDate |
Date : During parsing, two digit years will be placed in the range startDate to startDate + 100 years . |
void setContext (DisplayContext context)
[icu]在格式化程序中设置特定的DisplayContext值,例如CAPITALIZATION_FOR_STANDALONE。 注意:对于getContext,请参阅DateFormat。
Parameters | |
---|---|
context |
DisplayContext : The DisplayContext value to set. |
void setDateFormatSymbols (DateFormatSymbols newFormatSymbols)
允许您设置日期/时间格式数据。
Parameters | |
---|---|
newFormatSymbols |
DateFormatSymbols : the new symbols |
void setNumberFormat (String fields, NumberFormat overrideNF)
允许用户为多个字段设置NumberFormat它可以是单个字段,如:“y”(年)或“M”(月)可以将多个字段组合在一起:“yMd”(年,月和日)注:1符号字段对于多个符号字段是足够的(所以“y”将覆盖“yy”,“yyy”)如果字段不是数字,则覆盖没有效果(如“MMM”将使用缩写,而不是数字字段)
Parameters | |
---|---|
fields |
String : the fields to override |
overrideNF |
NumberFormat : the NumbeferFormat used |
Throws | |
---|---|
IllegalArgumentException |
when the fields contain invalid field |
void setNumberFormat (NumberFormat newNumberFormat)
覆盖超类方法,并且此方法还清除之前由 setNumberFormat(String, NumberFormat)
设置的每个字段的NumberFormat实例
Parameters | |
---|---|
newNumberFormat |
NumberFormat : the given new NumberFormat. |
void setTimeZoneFormat (TimeZoneFormat tzfmt)
[icu]允许您设置时区格式化程序。
Parameters | |
---|---|
tzfmt |
TimeZoneFormat : the new time zone formatter |
String toLocalizedPattern ()
返回描述此日期格式的本地化模式字符串。
Returns | |
---|---|
String |
DateFormatSymbols getSymbols ()
子类访问DateFormatSymbols的方法。
Returns | |
---|---|
DateFormatSymbols |
int matchQuarterString (String text, int start, int field, String[] data, Calendar cal)
尝试将给定位置上的文本与季度字符串数组进行匹配。 由于数组中的多个字符串可能匹配(例如,如果数组包含“a”,“ab”和“abc”,全部匹配输入字符串“abcd”),返回最长匹配。 作为副作用,给定字段cal
被设置为最佳匹配的索引,如果有的话。
Parameters | |
---|---|
text |
String : the time text being parsed. |
start |
int : where to start parsing. |
field |
int : the date field being parsed. |
data |
String : the string array to parsed. |
cal |
Calendar
|
Returns | |
---|---|
int |
the new start position if matching succeeded; a negative number indicating matching failure, otherwise. As a side effect, sets the cal field field to the index of the best match, if matching succeeded. |
int matchString (String text, int start, int field, String[] data, Calendar cal)
尝试将给定位置上的文本与字符串数组进行匹配。 由于数组中的多个字符串可能匹配(例如,如果数组包含“a”,“ab”和“abc”,全部匹配输入字符串“abcd”),返回最长匹配。 作为副作用,给定字段cal
被设置为最佳匹配的索引,如果有的话。
Parameters | |
---|---|
text |
String : the time text being parsed. |
start |
int : where to start parsing. |
field |
int : the date field being parsed. |
data |
String : the string array to parsed. |
Returns | |
---|---|
int |
the new start position if matching succeeded; a negative number indicating matching failure, otherwise. As a side effect, sets the cal field field to the index of the best match, if matching succeeded. |
DateFormat.Field patternCharToDateFormatField (char ch)
返回与指定格式模式字符关联的DateFormat.Field常量。
Parameters | |
---|---|
ch |
char : The pattern character |
Returns | |
---|---|
DateFormat.Field |
DateFormat.Field associated with the pattern character |
String subFormat (char ch, int count, int beginOffset, FieldPosition pos, DateFormatSymbols fmtData, Calendar cal)
根据模式字符格式化单个字段。 子类可以重写此方法以修改或添加格式化功能。
Parameters | |
---|---|
ch |
char : the pattern character |
count |
int : the number of times ch is repeated in the pattern |
beginOffset |
int : the offset of the output string at the start of this field; used to set pos when appropriate |
pos |
FieldPosition : receives the position of a field, when appropriate |
fmtData |
DateFormatSymbols : the symbols for this formatter |
cal |
Calendar
|
Returns | |
---|---|
String |
Throws | |
---|---|
IllegalArgumentException |
int subParse (String text, int start, char ch, int count, boolean obeyCount, boolean allowNegative, boolean[] ambiguousYear, Calendar cal)
受保护的方法,将输入字符串的一个字段转换为cal
的数字字段值。 返回-start(对于ParsePosition)如果失败。 子类可以重写此方法来修改或添加解析功能。
Parameters | |
---|---|
text |
String : the time text to be parsed. |
start |
int : where to start parsing. |
ch |
char : the pattern character for the date field text to be parsed. |
count |
int : the count of a pattern character. |
obeyCount |
boolean : if true, then the next field directly abuts this one, and we should use the count to know when to stop parsing. |
allowNegative |
boolean
|
ambiguousYear |
boolean : return parameter; upon return, if ambiguousYear[0] is true, then a two-digit year was parsed and may need to be readjusted. |
Returns | |
---|---|
int |
the new start position if matching succeeded; a negative number indicating matching failure, otherwise. As a side effect, set the appropriate field of cal with the parsed value. |
String zeroPaddingNumber (long value, int minDigits, int maxDigits)
使用指定的最小和最大位数格式化数字。
Parameters | |
---|---|
value |
long
|
minDigits |
int
|
maxDigits |
int
|
Returns | |
---|---|
String |