java.lang.Object
org.miaixz.bus.core.center.date.format.FormatManager
全局自定义日期格式管理器,用于定义用户指定的日期格式与格式化/解析规则的映射。
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionformat(TemporalAccessor temporalAccessor, CharSequence format) 使用自定义格式格式化时间对象。format(Date date, CharSequence format) 使用自定义格式格式化日期。static FormatManager获取FormatManager的单例实例。booleanisCustomFormat(String format) 检查是否为自定义格式化规则。booleanisCustomParse(String format) 检查是否为自定义解析规则。parse(CharSequence date, String format) 使用自定义格式解析日期字符串。registerFormatter(String format, Function<Date, String> func) 注册日期格式化规则。registerParser(String format, Function<CharSequence, Date> func) 注册日期解析规则。
-
Constructor Details
-
FormatManager
public FormatManager()构造函数,初始化预设的格式化与解析规则。
-
-
Method Details
-
getInstance
获取FormatManager的单例实例。- Returns:
- FormatManager单例
-
registerFormatter
注册日期格式化规则。- Parameters:
format- 格式标识func- 格式化函数- Returns:
- 当前FormatManager实例
- Throws:
IllegalArgumentException- 如果format或func为null
-
registerParser
注册日期解析规则。- Parameters:
format- 格式标识func- 解析函数- Returns:
- 当前FormatManager实例
- Throws:
IllegalArgumentException- 如果format或func为null
-
isCustomFormat
检查是否为自定义格式化规则。- Parameters:
format- 格式标识- Returns:
- 是否为自定义格式化规则
-
isCustomParse
检查是否为自定义解析规则。- Parameters:
format- 格式标识- Returns:
- 是否为自定义解析规则
-
format
使用自定义格式格式化日期。- Parameters:
date- 日期对象format- 自定义格式标识- Returns:
- 格式化后的字符串,若无对应规则返回null
-
format
使用自定义格式格式化时间对象。- Parameters:
temporalAccessor- 时间对象format- 自定义格式标识- Returns:
- 格式化后的字符串,若无对应规则返回null
-
parse
使用自定义格式解析日期字符串。- Parameters:
date- 日期字符串format- 自定义格式标识- Returns:
- 解析后的日期对象,若无对应规则返回null
-