Module bus.core

Class DatePattern

java.lang.Object
org.miaixz.bus.core.center.date.format.DatePattern

public class DatePattern extends Object
日期格式表达式类,用于解析和格式化日期时间。
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • DatePattern

      public DatePattern(String patternStr, Locale locale, TimeZone timeZone)
      构造函数,初始化日期格式表达式。
      Parameters:
      patternStr - 日期表达式字符串
      locale - 地域信息
      timeZone - 时区
  • Method Details

    • parseToken

      protected static String parseToken(String pattern, int[] indexRef)
      解析日期格式表达式中的标记。
      Parameters:
      pattern - 格式表达式字符串
      indexRef - 索引引用数组
      Returns:
      解析出的标记
    • selectNumberRule

      protected static DatePattern.NumberRule selectNumberRule(int field, int padding)
      根据字段和填充长度选择合适的数字规则。
      Parameters:
      field - 日期字段
      padding - 填充长度
      Returns:
      数字规则
    • getEstimateLength

      public int getEstimateLength()
      获取估算的格式化后字符串长度。
      Returns:
      估算长度
    • applyRules

      public <B extends Appendable> B applyRules(Calendar calendar, B buf)
      根据指定格式,将日期时间格式化到输出缓冲区。
      Type Parameters:
      B - Appendable实现类(如StringBuilder或StringBuffer)
      Parameters:
      calendar - 日历对象
      buf - 输出缓冲区
      Returns:
      格式化后的Appendable对象
      Throws:
      DateException - 如果发生I/O错误