java.lang.Object
java.text.Format
org.miaixz.bus.core.center.date.format.FormatBuilder
- All Implemented Interfaces:
Serializable,Cloneable,DateParser,PositionDateParser,DatePrinter,FormatPrinter
线程安全的日期格式化类,替代
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 TypeMethodDescriptionboolean判断是否与另一个对象相等。format(long millis) 格式化毫秒时间。<B extends Appendable>
Bformat(long millis, B buf) 格式化毫秒时间到指定缓冲区。format(Object object, StringBuffer toAppendTo, FieldPosition pos) 格式化对象到字符串缓冲区。格式化日历对象。<B extends Appendable>
B格式化日历对象到指定缓冲区。格式化日期对象。<B extends Appendable>
B格式化日期对象到指定缓冲区。static 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实例。获取与当前格式兼容的DateTimeFormatter。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 DateTimeFormattergetDateTimeInstance(String pattern) 创建DateTimeFormatter,使用系统默认时区和地域。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()获取对象的哈希码。parse(CharSequence source) 解析日期字符串。booleanparse(CharSequence source, ParsePosition pos, Calendar calendar) 解析日期字符串到日历对象。parseObject(String source, ParsePosition pos) 解析日期字符串到对象。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.miaixz.bus.core.center.date.format.parser.PositionDateParser
parse, parseCalendar
-
Constructor Details
-
FormatBuilder
构造函数,初始化日期格式化器。- Parameters:
pattern- 使用SimpleDateFormat兼容的日期格式timeZone- 非空时区locale- 日期地域- Throws:
NullPointerException- 如果pattern、timeZone或locale为null
-
FormatBuilder
构造函数,初始化日期格式化器,允许指定世纪起始时间。- Parameters:
pattern- 使用SimpleDateFormat兼容的日期格式timeZone- 非空时区locale- 日期地域centuryStart- 两位的默认世纪起始时间,若为null则为当前时间前80年- Throws:
NullPointerException- 如果pattern、timeZone或locale为null
-
-
Method Details
-
getInstance
获取默认格式和地域的FormatBuilder实例。- Returns:
- FormatBuilder实例
-
getInstance
获取指定格式的FormatBuilder实例,使用默认时区和地域。- Parameters:
pattern- 日期格式- Returns:
- FormatBuilder实例
- Throws:
IllegalArgumentException- 如果日期格式无效
-
getInstance
获取指定格式和时区的FormatBuilder实例。- Parameters:
pattern- 日期格式timeZone- 时区- Returns:
- FormatBuilder实例
- Throws:
IllegalArgumentException- 如果日期格式无效
-
getInstance
获取指定格式和地域的FormatBuilder实例。- Parameters:
pattern- 日期格式locale- 地域- Returns:
- FormatBuilder实例
- Throws:
IllegalArgumentException- 如果日期格式无效
-
getInstance
获取指定格式、时区和地域的FormatBuilder实例。- Parameters:
pattern- 日期格式timeZone- 时区locale- 地域- Returns:
- FormatBuilder实例
- Throws:
IllegalArgumentException- 如果日期格式无效
-
getDateInstance
获取指定日期样式的FormatBuilder实例。- Parameters:
style- 日期样式(FULL、LONG、MEDIUM或SHORT)- Returns:
- FormatBuilder实例
-
getDateInstance
获取指定日期样式和地域的FormatBuilder实例。- Parameters:
style- 日期样式(FULL、LONG、MEDIUM或SHORT)locale- 地域- Returns:
- FormatBuilder实例
-
getDateInstance
获取指定日期样式和时区的FormatBuilder实例。- Parameters:
style- 日期样式(FULL、LONG、MEDIUM或SHORT)timeZone- 时区- Returns:
- FormatBuilder实例
-
getDateInstance
获取指定日期样式、时区和地域的FormatBuilder实例。- Parameters:
style- 日期样式(FULL、LONG、MEDIUM或SHORT)timeZone- 时区locale- 地域- Returns:
- FormatBuilder实例
-
getTimeInstance
获取指定时间样式的FormatBuilder实例。- Parameters:
style- 时间样式(FULL、LONG、MEDIUM或SHORT)- Returns:
- FormatBuilder实例
-
getTimeInstance
获取指定时间样式和地域的FormatBuilder实例。- Parameters:
style- 时间样式(FULL、LONG、MEDIUM或SHORT)locale- 地域- Returns:
- FormatBuilder实例
-
getTimeInstance
获取指定时间样式和时区的FormatBuilder实例。- Parameters:
style- 时间样式(FULL、LONG、MEDIUM或SHORT)timeZone- 时区- Returns:
- FormatBuilder实例
-
getTimeInstance
获取指定时间样式、时区和地域的FormatBuilder实例。- Parameters:
style- 时间样式(FULL、LONG、MEDIUM或SHORT)timeZone- 时区locale- 地域- Returns:
- FormatBuilder实例
-
getDateTimeInstance
获取指定日期和时间样式的FormatBuilder实例。- Parameters:
dateStyle- 日期样式(FULL、LONG、MEDIUM或SHORT)timeStyle- 时间样式(FULL、LONG、MEDIUM或SHORT)- Returns:
- FormatBuilder实例
-
getDateTimeInstance
获取指定日期、时间样式和地域的FormatBuilder实例。- Parameters:
dateStyle- 日期样式(FULL、LONG、MEDIUM或SHORT)timeStyle- 时间样式(FULL、LONG、MEDIUM或SHORT)locale- 地域- Returns:
- FormatBuilder实例
-
getDateTimeInstance
获取指定日期、时间样式和时区的FormatBuilder实例。- Parameters:
dateStyle- 日期样式(FULL、LONG、MEDIUM或SHORT)timeStyle- 时间样式(FULL、LONG、MEDIUM或SHORT)timeZone- 时区- Returns:
- FormatBuilder实例
-
getDateTimeInstance
public static FormatBuilder getDateTimeInstance(int dateStyle, int timeStyle, TimeZone timeZone, Locale locale) 获取指定日期、时间样式、时区和地域的FormatBuilder实例。- Parameters:
dateStyle- 日期样式(FULL、LONG、MEDIUM或SHORT)timeStyle- 时间样式(FULL、LONG、MEDIUM或SHORT)timeZone- 时区locale- 地域- Returns:
- FormatBuilder实例
-
getDateTimeInstance
创建DateTimeFormatter,使用系统默认时区和地域。- Parameters:
pattern- 日期格式- Returns:
- DateTimeFormatter实例
-
format
格式化对象到字符串缓冲区。 -
format
格式化毫秒时间。- Specified by:
formatin interfaceFormatPrinter- Parameters:
millis- 毫秒时间- Returns:
- 格式化后的字符串
-
format
格式化日期对象。- Specified by:
formatin interfaceFormatPrinter- Parameters:
date- 日期对象- Returns:
- 格式化后的字符串
-
format
格式化日历对象。- Specified by:
formatin interfaceFormatPrinter- Parameters:
calendar- 日历对象- Returns:
- 格式化后的字符串
-
format
格式化毫秒时间到指定缓冲区。- Specified by:
formatin interfaceFormatPrinter- Type Parameters:
B- Appendable类型- Parameters:
millis- 毫秒时间buf- 输出缓冲区- Returns:
- 格式化后的缓冲区
-
format
格式化日期对象到指定缓冲区。- Specified by:
formatin interfaceFormatPrinter- Type Parameters:
B- Appendable类型- Parameters:
date- 日期对象buf- 输出缓冲区- Returns:
- 格式化后的缓冲区
-
format
格式化日历对象到指定缓冲区。- Specified by:
formatin interfaceFormatPrinter- Type Parameters:
B- Appendable类型- Parameters:
calendar- 日历对象buf- 输出缓冲区- Returns:
- 格式化后的缓冲区
-
parse
解析日期字符串。- Specified by:
parsein interfaceDateParser- Parameters:
source- 日期字符串- Returns:
- 解析后的日期对象
- Throws:
DateException- 如果解析失败
-
parse
解析日期字符串到日历对象。- Specified by:
parsein interfacePositionDateParser- Parameters:
source- 日期字符串pos- 解析位置calendar- 日历对象- Returns:
- 如果解析成功返回true
-
parseObject
解析日期字符串到对象。- Specified by:
parseObjectin classFormat- Parameters:
source- 日期字符串pos- 解析位置- Returns:
- 解析后的对象
-
getPattern
获取日期格式模式。- Specified by:
getPatternin interfaceDatePrinter- Returns:
- 日期格式模式
-
getTimeZone
获取时区。- Specified by:
getTimeZonein interfaceDatePrinter- Returns:
- 时区
-
getLocale
获取地域。- Specified by:
getLocalein interfaceDatePrinter- Returns:
- 地域
-
getMaxLengthEstimate
public int getMaxLengthEstimate()估算格式化后的最大字符串长度。- Returns:
- 最大长度估算
-
getDateTimeFormatter
获取与当前格式兼容的DateTimeFormatter。- Returns:
- DateTimeFormatter实例
-
equals
判断是否与另一个对象相等。 -
hashCode
public int hashCode()获取对象的哈希码。 -
toString
返回对象的字符串表示。
-