Class FormatBuilder
java.lang.Object
java.text.Format
org.miaixz.bus.core.center.date.format.FormatBuilder
- All Implemented Interfaces:
Serializable,Cloneable,DateParser,PositionDateParser,DatePrinter,FormatPrinter
FastFormat 是一个线程安全的
SimpleDateFormat 实现。
通过以下静态方法获得此对象:
getInstance(String, TimeZone, Locale)
getDateInstance(int, TimeZone, Locale)
getTimeInstance(int, TimeZone, Locale)
getDateTimeInstance(int, int, TimeZone, Locale)
- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.text.Format
Format.Field -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFormatBuilder(String pattern, TimeZone timeZone, Locale locale) 构造protectedFormatBuilder(String pattern, TimeZone timeZone, Locale locale, Date centuryStart) 构造 -
Method Summary
Modifier and TypeMethodDescriptionbooleanformat(long millis) 格式化日期表示的毫秒数<B extends Appendable>
Bformat(long millis, B buf) Formats a millisecondlongvalue into the suppliedAppendable.format(Object obj, StringBuffer toAppendTo, FieldPosition pos) Formats aCalendarobject.<B extends Appendable>
BFormats aCalendarobject into the suppliedAppendable.使用GregorianCalendar格式化Date<B extends Appendable>
BFormats aDateobject into the suppliedAppendableusing aGregorianCalendar.static FormatBuildergetDateInstance(int style) 获得 FastFormat 实例 支持缓存static FormatBuildergetDateInstance(int style, Locale locale) 获得 FastFormat 实例 支持缓存static FormatBuildergetDateInstance(int style, TimeZone timeZone) 获得 FastFormat 实例 支持缓存static FormatBuildergetDateInstance(int style, TimeZone timeZone, Locale locale) 获得 FastFormat 实例 支持缓存便捷获取 DateTimeFormatter 由于Fields很大一部分的格式没有提供DateTimeFormatter,因此这里提供快捷获取方式static FormatBuildergetDateTimeInstance(int dateStyle, int timeStyle) 获得 FastFormat 实例 支持缓存static FormatBuildergetDateTimeInstance(int dateStyle, int timeStyle, Locale locale) 获得 FastFormat 实例 支持缓存static FormatBuildergetDateTimeInstance(int dateStyle, int timeStyle, TimeZone timeZone) 获得 FastFormat 实例 支持缓存static FormatBuildergetDateTimeInstance(int dateStyle, int timeStyle, TimeZone timeZone, Locale locale) 获得 FastFormat 实例 支持缓存static DateTimeFormattergetDateTimeInstance(String pattern) 创建并为DateTimeFormatter赋予默认时区和位置信息,默认值为系统默认值。static FormatBuilder获得 FastDateFormat实例,使用默认格式和地区static FormatBuildergetInstance(String pattern) 获得 FastFormat 实例,使用默认地区 支持缓存static FormatBuildergetInstance(String pattern, Locale locale) 获得 FastFormat 实例 支持缓存static FormatBuildergetInstance(String pattern, TimeZone timeZone) 获得 FastFormat 实例 支持缓存static FormatBuildergetInstance(String pattern, TimeZone timeZone, Locale locale) 获得 FastFormat 实例 支持缓存获得 日期地理位置int估算生成的日期字符串长度 实际生成的字符串长度小于或等于此值获得日期格式化或者转换的格式static FormatBuildergetTimeInstance(int style) 获得 FastFormat 实例 支持缓存static FormatBuildergetTimeInstance(int style, Locale locale) 获得 FastFormat 实例 支持缓存static FormatBuildergetTimeInstance(int style, TimeZone timeZone) 获得 FastFormat 实例 支持缓存static FormatBuildergetTimeInstance(int style, TimeZone timeZone, Locale locale) 获得 FastFormat 实例 支持缓存获得时区inthashCode()parse(CharSequence source) 将日期字符串解析并转换为Date对象parse(CharSequence source, ParsePosition pos) 将日期字符串解析并转换为Date对象 等价于DateFormat.parse(String, ParsePosition)booleanparse(CharSequence source, ParsePosition pos, Calendar calendar) parseObject(String source, ParsePosition pos) toString()Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
-
Field Details
-
FULL
public static final int FULLFULL locale dependent date or time style.- See Also:
-
LONG
public static final int LONGLONG locale dependent date or time style.- See Also:
-
MEDIUM
public static final int MEDIUMMEDIUM locale dependent date or time style.- See Also:
-
SHORT
public static final int SHORTSHORT locale dependent date or time style.- See Also:
-
-
Constructor Details
-
FormatBuilder
构造- Parameters:
pattern- 使用SimpleDateFormat相同的日期格式timeZone- 非空时区TimeZonelocale-Locale日期地理位置- Throws:
NullPointerException- if pattern, timeZone, or locale is null.
-
FormatBuilder
构造- Parameters:
pattern- 使用SimpleDateFormat相同的日期格式timeZone- 非空时区TimeZonelocale-Locale日期地理位置centuryStart- The start of the 100 year period to use as the "default century" for 2 digit year parsing. If centuryStart is null, defaults to now - 80 years- Throws:
NullPointerException- if pattern, timeZone, or locale is null.
-
-
Method Details
-
getInstance
获得 FastDateFormat实例,使用默认格式和地区- Returns:
- FastFormat
-
getInstance
获得 FastFormat 实例,使用默认地区 支持缓存- Parameters:
pattern- 使用SimpleDateFormat相同的日期格式- Returns:
- FastFormat
- Throws:
IllegalArgumentException- 日期格式问题
-
getInstance
获得 FastFormat 实例 支持缓存- Parameters:
pattern- 使用SimpleDateFormat相同的日期格式timeZone- 时区TimeZone- Returns:
- FastFormat
- Throws:
IllegalArgumentException- 日期格式问题
-
getInstance
获得 FastFormat 实例 支持缓存- Parameters:
pattern- 使用SimpleDateFormat相同的日期格式locale-Locale日期地理位置- Returns:
- FastFormat
- Throws:
IllegalArgumentException- 日期格式问题
-
getInstance
获得 FastFormat 实例 支持缓存- Parameters:
pattern- 使用SimpleDateFormat相同的日期格式timeZone- 时区TimeZonelocale-Locale日期地理位置- Returns:
- FastFormat
- Throws:
IllegalArgumentException- 日期格式问题
-
getDateInstance
获得 FastFormat 实例 支持缓存- Parameters:
style- date style: FULL, LONG, MEDIUM, or SHORT- Returns:
- 本地化 FastFormat
-
getDateInstance
获得 FastFormat 实例 支持缓存- Parameters:
style- date style: FULL, LONG, MEDIUM, or SHORTlocale-Locale日期地理位置- Returns:
- 本地化 FastFormat
-
getDateInstance
获得 FastFormat 实例 支持缓存- Parameters:
style- date style: FULL, LONG, MEDIUM, or SHORTtimeZone- 时区TimeZone- Returns:
- 本地化 FastFormat
-
getDateInstance
获得 FastFormat 实例 支持缓存 -
getTimeInstance
获得 FastFormat 实例 支持缓存- Parameters:
style- time style: FULL, LONG, MEDIUM, or SHORT- Returns:
- 本地化 FastFormat
-
getTimeInstance
获得 FastFormat 实例 支持缓存- Parameters:
style- time style: FULL, LONG, MEDIUM, or SHORTlocale-Locale日期地理位置- Returns:
- 本地化 FastFormat
-
getTimeInstance
获得 FastFormat 实例 支持缓存- Parameters:
style- time style: FULL, LONG, MEDIUM, or SHORTtimeZone- optional time zone, overrides time zone of formatted time- Returns:
- 本地化 FastFormat
-
getTimeInstance
获得 FastFormat 实例 支持缓存- Parameters:
style- time style: FULL, LONG, MEDIUM, or SHORTtimeZone- optional time zone, overrides time zone of formatted timelocale-Locale日期地理位置- Returns:
- 本地化 FastFormat
-
getDateTimeInstance
获得 FastFormat 实例 支持缓存- Parameters:
dateStyle- date style: FULL, LONG, MEDIUM, or SHORTtimeStyle- time style: FULL, LONG, MEDIUM, or SHORT- Returns:
- 本地化 FastFormat
-
getDateTimeInstance
获得 FastFormat 实例 支持缓存- Parameters:
dateStyle- date style: FULL, LONG, MEDIUM, or SHORTtimeStyle- time style: FULL, LONG, MEDIUM, or SHORTlocale-Locale日期地理位置- Returns:
- 本地化 FastFormat
-
getDateTimeInstance
获得 FastFormat 实例 支持缓存- Parameters:
dateStyle- date style: FULL, LONG, MEDIUM, or SHORTtimeStyle- time style: FULL, LONG, MEDIUM, or SHORTtimeZone- 时区TimeZone- Returns:
- 本地化 FastFormat
-
getDateTimeInstance
public static FormatBuilder getDateTimeInstance(int dateStyle, int timeStyle, TimeZone timeZone, Locale locale) 获得 FastFormat 实例 支持缓存 -
getDateTimeInstance
创建并为DateTimeFormatter赋予默认时区和位置信息,默认值为系统默认值。- Parameters:
pattern- 日期格式- Returns:
DateTimeFormatter
-
format
-
format
Description copied from interface:FormatPrinter格式化日期表示的毫秒数- Specified by:
formatin interfaceFormatPrinter- Parameters:
millis- 日期毫秒数- Returns:
- the formatted string
-
format
Description copied from interface:FormatPrinter使用GregorianCalendar格式化Date- Specified by:
formatin interfaceFormatPrinter- Parameters:
date- 日期Date- Returns:
- 格式化后的字符串
-
format
Description copied from interface:FormatPrinterFormats aCalendarobject.格式化
Calendar- Specified by:
formatin interfaceFormatPrinter- Parameters:
calendar-Calendar- Returns:
- 格式化后的字符串
-
format
Description copied from interface:FormatPrinterFormats a millisecondlongvalue into the suppliedAppendable.- Specified by:
formatin interfaceFormatPrinter- Type Parameters:
B- the Appendable class type, usually StringBuilder or StringBuffer.- Parameters:
millis- the millisecond value to formatbuf- the buffer to format into- Returns:
- the specified string buffer
-
format
Description copied from interface:FormatPrinterFormats aDateobject into the suppliedAppendableusing aGregorianCalendar.- Specified by:
formatin interfaceFormatPrinter- Type Parameters:
B- the Appendable class type, usually StringBuilder or StringBuffer.- Parameters:
date- the date to formatbuf- the buffer to format into- Returns:
- the specified string buffer
-
format
Description copied from interface:FormatPrinterFormats aCalendarobject into the suppliedAppendable. The TimeZone set on the Calendar is only used to adjust the time offset. The TimeZone specified during the construction of the Parser will determine the TimeZone used in the formatted string.- Specified by:
formatin interfaceFormatPrinter- Type Parameters:
B- the Appendable class type, usually StringBuilder or StringBuffer.- Parameters:
calendar- the calendar to formatbuf- the buffer to format into- Returns:
- the specified string buffer
-
parse
Description copied from interface:DateParser将日期字符串解析并转换为Date对象- Specified by:
parsein interfaceDateParser- Parameters:
source- 被解析的日期字符串- Returns:
Date对象- Throws:
DateException- 转换异常,被转换的字符串格式错误。
-
parse
Description copied from interface:PositionDateParser将日期字符串解析并转换为Date对象 等价于DateFormat.parse(String, ParsePosition)- Specified by:
parsein interfacePositionDateParser- Parameters:
source- 日期字符串pos-ParsePosition- Returns:
Date
-
parse
Description copied from interface:PositionDateParser- Specified by:
parsein interfacePositionDateParser- Parameters:
source- 被转换的日期字符串pos- 定义开始转换的位置,转换结束后更新转换到的位置calendar- 解析并更新的Calendar- Returns:
- 解析成功返回
true,否则返回false
-
parseObject
- Specified by:
parseObjectin classFormat
-
getPattern
Description copied from interface:DatePrinter获得日期格式化或者转换的格式- Specified by:
getPatternin interfaceDatePrinter- Returns:
SimpleDateFormat兼容的格式
-
getTimeZone
Description copied from interface:DatePrinter获得时区- Specified by:
getTimeZonein interfaceDatePrinter- Returns:
TimeZone
-
getLocale
Description copied from interface:DatePrinter获得 日期地理位置- Specified by:
getLocalein interfaceDatePrinter- Returns:
Locale
-
getMaxLengthEstimate
public int getMaxLengthEstimate()估算生成的日期字符串长度 实际生成的字符串长度小于或等于此值- Returns:
- 日期字符串长度
-
getDateTimeFormatter
便捷获取 DateTimeFormatter 由于Fields很大一部分的格式没有提供DateTimeFormatter,因此这里提供快捷获取方式- Returns:
- DateTimeFormatter
-
equals
-
hashCode
public int hashCode() -
toString
-