Class ChineseDate

java.lang.Object
org.miaixz.bus.core.center.date.chinese.ChineseDate

public class ChineseDate extends Object
农历日期工具,最大支持到2099年,支持:
  • 通过公历日期构造获取对应农历
  • 通过农历日期直接构造

规范参考:GB/T 33661-2017

Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • ChineseDate

      public ChineseDate(Date date)
      通过公历日期构造
      Parameters:
      date - 公历日期
    • ChineseDate

      public ChineseDate(LocalDate localDate)
      通过公历日期构造
      Parameters:
      localDate - 公历日期
    • ChineseDate

      public ChineseDate(int chineseYear, int chineseMonth, int chineseDay)
      构造方法传入日期 此方法自动判断闰月,如果chineseMonth为本年的闰月,则按照闰月计算
      Parameters:
      chineseYear - 农历年
      chineseMonth - 农历月,1表示一月(正月)
      chineseDay - 农历日,1表示初一
    • ChineseDate

      public ChineseDate(int chineseYear, int chineseMonth, int chineseDay, boolean isLeapMonth)
      构造方法传入日期 通过isLeapMonth参数区分是否闰月,如五月是闰月,当isLeapMonth为true时,表示润五月,false表示五月
      Parameters:
      chineseYear - 农历年
      chineseMonth - 农历月,1表示一月(正月),如果isLeapMonth为true,1表示润一月
      chineseDay - 农历日,1表示初一
      isLeapMonth - 当前月份是否闰月
  • Method Details

    • getChineseYear

      public int getChineseYear()
      获得农历年份
      Returns:
      返回农历年份
    • getGregorianYear

      public int getGregorianYear()
      获取公历的年
      Returns:
      公历年
    • getMonth

      public int getMonth()
      获取农历的月,从1开始计数 此方法返回实际的月序号,如一月是闰月,则一月返回1,润一月返回2
      Returns:
      农历的月
    • getGregorianMonthBase1

      public int getGregorianMonthBase1()
      获取公历的月,从1开始计数
      Returns:
      公历月
    • getGregorianMonth

      public int getGregorianMonth()
      获取公历的月,从0开始计数
      Returns:
      公历月
    • isLeapMonth

      public boolean isLeapMonth()
      当前农历月份是否为闰月
      Returns:
      是否为闰月
    • getChineseMonth

      public String getChineseMonth()
      获得农历月份(中文,例如二月,十二月,或者润一月)
      Returns:
      返回农历月份
    • getChineseMonthName

      public String getChineseMonthName()
      获得农历月称呼(中文,例如二月,腊月,或者润正月)
      Returns:
      返回农历月份称呼
    • getChineseMonth

      public String getChineseMonth(boolean isTraditional)
      获得农历月份(中文,例如二月,十二月,或者润一月)
      Parameters:
      isTraditional - 是否传统表示,例如一月传统表示为正月
      Returns:
      返回农历月份
    • getDay

      public int getDay()
      获取农历的日,从1开始计数
      Returns:
      农历的日,从1开始计数
    • getGregorianDay

      public int getGregorianDay()
      获取公历的日
      Returns:
      公历日
    • getChineseDay

      public String getChineseDay()
      获得农历日
      Returns:
      获得农历日
    • getGregorianDate

      public Date getGregorianDate()
      获取公历的Date
      Returns:
      公历Date
    • getGregorianCalendar

      public Calendar getGregorianCalendar()
      获取公历的Calendar
      Returns:
      公历Calendar
    • getFestivals

      public String getFestivals()
      获得节日,闰月不计入节日中
      Returns:
      获得农历节日
    • getChineseZodiac

      public String getChineseZodiac()
      获得年份生肖
      Returns:
      获得年份生肖
    • getCyclical

      public String getCyclical()
      获得年的天干地支
      Returns:
      获得天干地支
    • getTerm

      public String getTerm()
      获得节气
      Returns:
      获得节气
    • toStringNormal

      public String toStringNormal()
      转换为标准的日期格式来表示农历日期 例如2020-01-13 如果存在闰月,显示闰月月份,如润二月显示2
      Returns:
      标准的日期格式
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(ChineseDateFormat format)
      获取标准化农历日期 支持格式
      1. ChineseDateFormat.GSS 干支纪年 数序纪月 数序纪日
      2. ChineseDateFormat.XSS 生肖纪年 数序纪月 数序纪日
      3. ChineseDateFormat.GXSS 干支生肖纪年 数序纪月(传统表示) 数序纪日日
      4. ChineseDateFormat.GSG 干支纪年 数序纪月 干支纪日
      5. ChineseDateFormat.GGG 干支纪年 干支纪月 干支纪日
      6. ChineseDateFormat.MIX 农历年年首所在的公历年份 干支纪年 数序纪月 数序纪日
      Parameters:
      format - 选择输出的标准格式
      Returns:
      获取的标准化农历日期
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object