Package org.aoju.bus.core.date.formatter
Class FormatBuilder
java.lang.Object
java.text.Format
org.aoju.bus.core.date.formatter.FormatBuilder
- All Implemented Interfaces:
Serializable,Cloneable,DateMotd,DatePrinter,DateParser,PositionDateParser
FormatBuilder 是一个线程安全的
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 -
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) 将毫秒long值格式化为提供的Appendableformat(Object object, StringBuffer toAppendTo, FieldPosition pos) 格式化Calendar对象<B extends Appendable>
B将Calendar对象格式化为提供的Appendable日历上设置的时区仅用于调整时间偏移。使用GregorianCalendar格式化Date<B extends Appendable>
B使用GregorianCalendar将Date对象格式化为提供的Appendablestatic FormatBuildergetDateInstance(int style) 获得FormatBuilder实例 支持缓存static FormatBuildergetDateInstance(int style, Locale locale) 获得FormatBuilder实例 支持缓存static FormatBuildergetDateInstance(int style, TimeZone timeZone) 获得FormatBuilder实例 支持缓存static FormatBuildergetDateInstance(int style, TimeZone timeZone, Locale locale) 获得FormatBuilder实例 支持缓存static FormatBuildergetDateTimeInstance(int dateStyle, int timeStyle) 获得FormatBuilder实例 支持缓存static FormatBuildergetDateTimeInstance(int dateStyle, int timeStyle, Locale locale) 获得FormatBuilder实例 支持缓存static FormatBuildergetDateTimeInstance(int dateStyle, int timeStyle, TimeZone timeZone) 获得FormatBuilder实例 支持缓存static FormatBuildergetDateTimeInstance(int dateStyle, int timeStyle, TimeZone timeZone, Locale locale) 获得FormatBuilder实例 支持缓存static FormatBuilder获得FormatBuilder实例,使用默认格式和地区static FormatBuildergetInstance(String pattern) 获得FormatBuilder实例,使用默认地区 支持缓存static FormatBuildergetInstance(String pattern, Locale locale) 获得FormatBuilder实例 支持缓存static FormatBuildergetInstance(String pattern, TimeZone timeZone) 获得FormatBuilder实例 支持缓存static FormatBuildergetInstance(String pattern, TimeZone timeZone, Locale locale) 获得FormatBuilder实例 支持缓存获得 日期地理位置int估算生成的日期字符串长度 实际生成的字符串长度小于或等于此值获得日期格式化或者转换的格式static FormatBuildergetTimeInstance(int style) 获得FormatBuilder实例 支持缓存static FormatBuildergetTimeInstance(int style, Locale locale) 获得FormatBuilder实例 支持缓存static FormatBuildergetTimeInstance(int style, TimeZone timeZone) 获得FormatBuilder实例 支持缓存static FormatBuildergetTimeInstance(int style, TimeZone timeZone, Locale locale) 获得FormatBuilder实例 支持缓存获得时区inthashCode()将日期字符串解析并转换为Date对象 等价于DateFormat.parse(String)parse(String source, ParsePosition pos) 将日期字符串解析并转换为Date对象 等价于DateFormat.parse(String, ParsePosition)booleanparse(String source, ParsePosition pos, Calendar calendar) 根据给定格式更新CalendarparseObject(String source, ParsePosition pos) 根据ParsePosition给定将日期字符串解析并转换为Date对象toString()Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObjectMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.aoju.bus.core.date.formatter.parser.DateParser
parseObject
-
Constructor Details
-
FormatBuilder
构造- Parameters:
pattern- 使用SimpleDateFormat相同的日期格式timeZone- 非空时区TimeZonelocale-Locale日期地理位置- Throws:
NullPointerException- 如果模式、时区或区域设置为空
-
FormatBuilder
构造- Parameters:
pattern- 使用SimpleDateFormat相同的日期格式timeZone- 非空时区TimeZonelocale-Locale日期地理位置centuryStart- 使用100年周期的开始作为2位数年解析的“默认世纪”。如果centuryStart为空,则默认为- 80年- Throws:
NullPointerException- 如果模式、时区或地区为空.
-
-
Method Details
-
getInstance
-
getInstance
获得FormatBuilder实例,使用默认地区 支持缓存- Parameters:
pattern- 使用SimpleDateFormat相同的日期格式- Returns:
FormatBuilder- Throws:
IllegalArgumentException- 日期格式问题
-
getInstance
获得FormatBuilder实例 支持缓存- Parameters:
pattern- 使用SimpleDateFormat相同的日期格式timeZone- 时区TimeZone- Returns:
FormatBuilder- Throws:
IllegalArgumentException- 日期格式问题
-
getInstance
获得FormatBuilder实例 支持缓存- Parameters:
pattern- 使用SimpleDateFormat相同的日期格式locale-Locale日期地理位置- Returns:
FormatBuilder- Throws:
IllegalArgumentException- 日期格式问题
-
getInstance
获得FormatBuilder实例 支持缓存- Parameters:
pattern- 使用SimpleDateFormat相同的日期格式timeZone- 时区TimeZonelocale-Locale日期地理位置- Returns:
FormatBuilder- Throws:
IllegalArgumentException- 日期格式问题
-
getDateInstance
获得FormatBuilder实例 支持缓存- Parameters:
style- 日期格式: FULL, LONG, MEDIUM, or SHORT- Returns:
- 本地化
FormatBuilder
-
getDateInstance
获得FormatBuilder实例 支持缓存- Parameters:
style- 日期格式: FULL, LONG, MEDIUM, or SHORTlocale-Locale日期地理位置- Returns:
- 本地化
FormatBuilder
-
getDateInstance
获得FormatBuilder实例 支持缓存- Parameters:
style- 日期格式: FULL, LONG, MEDIUM, or SHORTtimeZone- 时区TimeZone- Returns:
- 本地化
FormatBuilder
-
getDateInstance
获得FormatBuilder实例 支持缓存- Parameters:
style- 日期格式: FULL, LONG, MEDIUM, or SHORTtimeZone- 时区TimeZonelocale-Locale日期地理位置- Returns:
- 本地化
FormatBuilder
-
getTimeInstance
获得FormatBuilder实例 支持缓存- Parameters:
style- 时间格式: FULL, LONG, MEDIUM, or SHORT- Returns:
- 本地化
FormatBuilder
-
getTimeInstance
获得FormatBuilder实例 支持缓存- Parameters:
style- 时间格式: FULL, LONG, MEDIUM, or SHORTlocale-Locale日期地理位置- Returns:
- 本地化
FormatBuilder
-
getTimeInstance
获得FormatBuilder实例 支持缓存- Parameters:
style- 时间格式: FULL, LONG, MEDIUM, or SHORTtimeZone- 可选时区,覆盖格式化时间的时区- Returns:
- 本地化
FormatBuilder
-
getTimeInstance
获得FormatBuilder实例 支持缓存- Parameters:
style- 时间格式: FULL, LONG, MEDIUM, or SHORTtimeZone- 可选时区,覆盖格式化时间的时区locale-Locale日期地理位置- Returns:
- 本地化
FormatBuilder
-
getDateTimeInstance
获得FormatBuilder实例 支持缓存- Parameters:
dateStyle- 日期格式: FULL, LONG, MEDIUM, or SHORTtimeStyle- 时间格式: FULL, LONG, MEDIUM, or SHORT- Returns:
- 本地化
FormatBuilder
-
getDateTimeInstance
获得FormatBuilder实例 支持缓存- Parameters:
dateStyle- 日期格式: FULL, LONG, MEDIUM, or SHORTtimeStyle- 时间格式: FULL, LONG, MEDIUM, or SHORTlocale-Locale日期地理位置- Returns:
- 本地化
FormatBuilder
-
getDateTimeInstance
获得FormatBuilder实例 支持缓存- Parameters:
dateStyle- 日期格式: FULL, LONG, MEDIUM, or SHORTtimeStyle- 时间格式: FULL, LONG, MEDIUM, or SHORTtimeZone- 时区TimeZone- Returns:
- 本地化
FormatBuilder
-
getDateTimeInstance
public static FormatBuilder getDateTimeInstance(int dateStyle, int timeStyle, TimeZone timeZone, Locale locale) 获得FormatBuilder实例 支持缓存- Parameters:
dateStyle- 日期格式: FULL, LONG, MEDIUM, or SHORTtimeStyle- 时间格式: FULL, LONG, MEDIUM, or SHORTtimeZone- 时区TimeZonelocale-Locale日期地理位置- Returns:
- 本地化
FormatBuilder
-
format
-
format
Description copied from interface:DatePrinter格式化日期表示的毫秒数- Specified by:
formatin interfaceDatePrinter- Parameters:
millis- 日期毫秒数- Returns:
- 格式化的字符串
-
format
Description copied from interface:DatePrinter使用GregorianCalendar格式化Date- Specified by:
formatin interfaceDatePrinter- Parameters:
date- 日期Date- Returns:
- 格式化后的字符串
-
format
Description copied from interface:DatePrinter格式化Calendar对象- Specified by:
formatin interfaceDatePrinter- Parameters:
calendar-Calendar- Returns:
- 格式化后的字符串
-
format
Description copied from interface:DatePrinter将毫秒long值格式化为提供的Appendable- Specified by:
formatin interfaceDatePrinter- Type Parameters:
B- 附加类类型,通常是StringBuilder或StringBuffer- Parameters:
millis- 要格式化的毫秒值buf- 要格式化为的缓冲区- Returns:
- 指定的字符串缓冲区
-
format
Description copied from interface:DatePrinter使用GregorianCalendar将Date对象格式化为提供的Appendable- Specified by:
formatin interfaceDatePrinter- Type Parameters:
B- 附加类类型,通常是StringBuilder或StringBuffer- Parameters:
date- 格式的日期buf- 要格式化为的缓冲区- Returns:
- 指定的字符串缓冲区
-
format
Description copied from interface:DatePrinter将Calendar对象格式化为提供的Appendable日历上设置的时区仅用于调整时间偏移。解析器构造期间指定的时区将确定格式化字符串中使用的时区- Specified by:
formatin interfaceDatePrinter- Type Parameters:
B- 附加类类型,通常是StringBuilder或StringBuffer- Parameters:
calendar- 要格式化的日历buf- 要格式化为的缓冲区- Returns:
- 指定的字符串缓冲区
-
parse
Description copied from interface:DateParser将日期字符串解析并转换为Date对象 等价于DateFormat.parse(String)- Specified by:
parsein interfaceDateParser- Parameters:
source- 被解析的日期字符串- Returns:
Date对象- Throws:
ParseException- 转换异常,被转换的字符串格式错误。
-
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根据给定格式更新Calendar- Specified by:
parsein interfacePositionDateParser- Parameters:
source- 被转换的日期字符串pos- 定义开始转换的位置,转换结束后更新转换到的位置calendar- 要将解析字段设置到其中的日历- Returns:
- true
-
parseObject
Description copied from interface:PositionDateParser根据ParsePosition给定将日期字符串解析并转换为Date对象- Specified by:
parseObjectin interfacePositionDateParser- Specified by:
parseObjectin classFormat- Parameters:
source- 应该解析其开头的Stringpos- 解析的位置- Returns:
java.util.date对象
-
getPattern
Description copied from interface:DateMotd获得日期格式化或者转换的格式- Specified by:
getPatternin interfaceDateMotd- Returns:
SimpleDateFormat兼容的格式
-
getTimeZone
Description copied from interface:DateMotd获得时区- Specified by:
getTimeZonein interfaceDateMotd- Returns:
TimeZone
-
getLocale
-
getMaxLengthEstimate
public int getMaxLengthEstimate()估算生成的日期字符串长度 实际生成的字符串长度小于或等于此值- Returns:
- 日期字符串长度
-
equals
-
hashCode
-
toString
-