Class FastDateParser

java.lang.Object
org.miaixz.bus.core.center.date.printer.SimpleDatePrinter
org.miaixz.bus.core.center.date.format.parser.FastDateParser
All Implemented Interfaces:
Serializable, DateParser, PositionDateParser, DatePrinter

public class FastDateParser extends SimpleDatePrinter implements PositionDateParser
SimpleDateFormat 的线程安全版本,用于解析日期字符串并转换为 Date 对象
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • FastDateParser

      public FastDateParser(String pattern, TimeZone timeZone, Locale locale)

      Constructs a new FastDateParser.

      Use FormatBuilder.getInstance(String, TimeZone, Locale) or another variation of the factory methods of FormatBuilder to get a cached FastDateParser instance.

      Parameters:
      pattern - non-null SimpleDateFormat compatible pattern
      timeZone - non-null time zone to use
      locale - non-null locale
    • FastDateParser

      public FastDateParser(String pattern, TimeZone timeZone, Locale locale, Date centuryStart)

      Constructs a new FastDateParser.

      Parameters:
      pattern - non-null SimpleDateFormat compatible pattern
      timeZone - non-null time zone to use
      locale - non-null locale
      centuryStart - The start of the century for 2 digit year parsing
  • Method Details

    • parse

      public Date parse(String source) throws DateException
      Description copied from interface: DateParser
      将日期字符串解析并转换为 Date 对象 等价于 DateFormat.parse(String)
      Specified by:
      parse in interface DateParser
      Parameters:
      source - 被解析的日期字符串
      Returns:
      Date对象
      Throws:
      DateException - 转换异常,被转换的字符串格式错误。
    • parse

      public Date parse(String source, ParsePosition pos)
      Description copied from interface: PositionDateParser
      将日期字符串解析并转换为 Date 对象 等价于 DateFormat.parse(String, ParsePosition)
      Specified by:
      parse in interface PositionDateParser
      Parameters:
      source - 日期字符串
      pos - ParsePosition
      Returns:
      Date
    • parse

      public boolean parse(String source, ParsePosition pos, Calendar calendar)
      Description copied from interface: PositionDateParser
      根据给定格式更新Calendar Upon success, the ParsePosition index is updated to indicate how much of the source text was consumed. Not all source text needs to be consumed. Upon parse failure, ParsePosition error index is updated to the offset of the source text which does not match the supplied format.
      Specified by:
      parse in interface PositionDateParser
      Parameters:
      source - 被转换的日期字符串
      pos - 定义开始转换的位置,转换结束后更新转换到的位置
      calendar - The calendar into which to set parsed fields.
      Returns:
      true, if source has been parsed (pos parsePosition is updated); otherwise false (and pos errorIndex is updated)