Class Lunar

java.lang.Object
cloud.opencode.base.date.lunar.Lunar
All Implemented Interfaces:
Serializable, Comparable<Lunar>

public final class Lunar extends Object implements Comparable<Lunar>, Serializable
Lunar (Chinese Calendar) date representation 农历(中国传统历法)日期表示

This class represents a date in the Chinese lunar calendar, including year, month, day, and leap month information.

此类表示中国农历中的日期,包括年、月、日和闰月信息。

Features | 主要功能:

  • Lunar date representation - 农历日期表示
  • Chinese zodiac support - 生肖支持
  • Heavenly stems and earthly branches - 天干地支
  • Chinese number formatting - 中文数字格式化

Usage Examples | 使用示例:

Lunar lunar = Lunar.of(2024, 1, 1, false);
String zodiac = lunar.getZodiac();  // "龙"
String chinese = lunar.toChinese(); // "二〇二四年正月初一"

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
  • Null-safe: Yes (with explicit null checks) - 空值安全: 是(有明确的空值检查)
Since:
JDK 25, opencode-base-date V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • of

      public static Lunar of(int year, int month, int day, boolean leapMonth)
      Creates a Lunar date 创建农历日期
      Parameters:
      year - the lunar year | 农历年
      month - the lunar month (1-12) | 农历月(1-12)
      day - the lunar day (1-30) | 农历日(1-30)
      leapMonth - whether this is a leap month | 是否为闰月
      Returns:
      the Lunar date | 农历日期
    • of

      public static Lunar of(int year, int month, int day)
      Creates a Lunar date (non-leap month) 创建农历日期(非闰月)
      Parameters:
      year - the lunar year | 农历年
      month - the lunar month (1-12) | 农历月(1-12)
      day - the lunar day (1-30) | 农历日(1-30)
      Returns:
      the Lunar date | 农历日期
    • getYear

      public int getYear()
      Gets the lunar year 获取农历年
      Returns:
      the year | 年
    • getMonth

      public int getMonth()
      Gets the lunar month 获取农历月
      Returns:
      the month (1-12) | 月(1-12)
    • getDay

      public int getDay()
      Gets the lunar day 获取农历日
      Returns:
      the day (1-30) | 日(1-30)
    • isLeapMonth

      public boolean isLeapMonth()
      Checks if this is a leap month 检查是否为闰月
      Returns:
      true if leap month | 如果是闰月返回true
    • getZodiac

      public String getZodiac()
      Gets the Chinese zodiac animal 获取生肖
      Returns:
      the zodiac animal | 生肖
    • getHeavenlyStem

      public String getHeavenlyStem()
      Gets the heavenly stem (天干) 获取天干
      Returns:
      the heavenly stem | 天干
    • getEarthlyBranch

      public String getEarthlyBranch()
      Gets the earthly branch (地支) 获取地支
      Returns:
      the earthly branch | 地支
    • getStemBranchYear

      public String getStemBranchYear()
      Gets the stem-branch year name (干支纪年) 获取干支纪年
      Returns:
      the stem-branch name | 干支名称
    • getChineseYear

      public String getChineseYear()
      Gets the full year representation in Chinese 获取完整的中文年份表示
      Returns:
      the Chinese year | 中文年份
    • getChineseMonth

      public String getChineseMonth()
      Gets the month name in Chinese 获取中文月份名称
      Returns:
      the Chinese month | 中文月份
    • getChineseDay

      public String getChineseDay()
      Gets the day name in Chinese 获取中文日期名称
      Returns:
      the Chinese day | 中文日期
    • toChinese

      public String toChinese()
      Converts to Chinese representation 转换为中文表示
      Returns:
      the Chinese date string | 中文日期字符串
    • toStemBranch

      public String toStemBranch()
      Converts to stem-branch representation 转换为干支表示
      Returns:
      the stem-branch date string | 干支日期字符串
    • compareTo

      public int compareTo(Lunar other)
      Specified by:
      compareTo in interface Comparable<Lunar>
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object