Class FastDatePrinter

java.lang.Object
org.miaixz.bus.core.center.date.printer.SimpleDatePrinter
org.miaixz.bus.core.center.date.printer.FastDatePrinter
All Implemented Interfaces:
Serializable, DatePrinter, FormatPrinter

public class FastDatePrinter extends SimpleDatePrinter implements FormatPrinter
SimpleDateFormat 的线程安全版本,用于将 Date 格式化输出 Thanks to Apache Commons Lang 3.5
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • FastDatePrinter

      public FastDatePrinter(String pattern, TimeZone timeZone, Locale locale)
      构造,内部使用
      Parameters:
      pattern - 使用SimpleDateFormat 相同的日期格式
      timeZone - 非空时区TimeZone
      locale - 非空Locale 日期地理位置
  • Method Details

    • parsePattern

      protected List<FastDatePrinter.Rule> parsePattern()
      Returns a list of Rules given a pattern.
      Returns:
      a List of Rule objects
      Throws:
      IllegalArgumentException - if pattern is invalid
    • parseToken

      protected String parseToken(String pattern, int[] indexRef)
      Performs the parsing of tokens.
      Parameters:
      pattern - the pattern
      indexRef - index references
      Returns:
      parsed token
    • selectNumberRule

      protected FastDatePrinter.NumberRule selectNumberRule(int field, int padding)
      Gets an appropriate rule for the padding required.
      Parameters:
      field - the field to get a rule for
      padding - the padding required
      Returns:
      a new rule with the correct padding
    • format

      public String format(Object obj)
      Formats a Date, Calendar or Long (milliseconds) object.
      Parameters:
      obj - the object to format
      Returns:
      The formatted value.
    • format

      public String format(long millis)
      Description copied from interface: FormatPrinter
      格式化日期表示的毫秒数
      Specified by:
      format in interface FormatPrinter
      Parameters:
      millis - 日期毫秒数
      Returns:
      the formatted string
    • format

      public String format(Date date)
      Description copied from interface: FormatPrinter
      使用 GregorianCalendar 格式化 Date
      Specified by:
      format in interface FormatPrinter
      Parameters:
      date - 日期 Date
      Returns:
      格式化后的字符串
    • format

      public String format(Calendar calendar)
      Description copied from interface: FormatPrinter
      Formats a Calendar object.

      格式化 Calendar

      Specified by:
      format in interface FormatPrinter
      Parameters:
      calendar - Calendar
      Returns:
      格式化后的字符串
    • format

      public <B extends Appendable> B format(long millis, B buf)
      Description copied from interface: FormatPrinter
      Formats a millisecond long value into the supplied Appendable.
      Specified by:
      format in interface FormatPrinter
      Type Parameters:
      B - the Appendable class type, usually StringBuilder or StringBuffer.
      Parameters:
      millis - the millisecond value to format
      buf - the buffer to format into
      Returns:
      the specified string buffer
    • format

      public <B extends Appendable> B format(Date date, B buf)
      Description copied from interface: FormatPrinter
      Formats a Date object into the supplied Appendable using a GregorianCalendar.
      Specified by:
      format in interface FormatPrinter
      Type Parameters:
      B - the Appendable class type, usually StringBuilder or StringBuffer.
      Parameters:
      date - the date to format
      buf - the buffer to format into
      Returns:
      the specified string buffer
    • format

      public <B extends Appendable> B format(Calendar calendar, B buf)
      Description copied from interface: FormatPrinter
      Formats a Calendar object into the supplied Appendable. 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:
      format in interface FormatPrinter
      Type Parameters:
      B - the Appendable class type, usually StringBuilder or StringBuffer.
      Parameters:
      calendar - the calendar to format
      buf - the buffer to format into
      Returns:
      the specified string buffer
    • getMaxLengthEstimate

      public int getMaxLengthEstimate()
      估算生成的日期字符串长度 实际生成的字符串长度小于或等于此值
      Returns:
      日期字符串长度