Class Lunar
java.lang.Object
cloud.opencode.base.date.lunar.Lunar
- All Implemented Interfaces:
Serializable, Comparable<Lunar>
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 Summary
Modifier and TypeMethodDescriptionintbooleanGets the day name in Chinese 获取中文日期名称Gets the month name in Chinese 获取中文月份名称Gets the full year representation in Chinese 获取完整的中文年份表示intgetDay()Gets the lunar day 获取农历日Gets the earthly branch (地支) 获取地支Gets the heavenly stem (天干) 获取天干intgetMonth()Gets the lunar month 获取农历月Gets the stem-branch year name (干支纪年) 获取干支纪年intgetYear()Gets the lunar year 获取农历年Gets the Chinese zodiac animal 获取生肖inthashCode()booleanChecks if this is a leap month 检查是否为闰月static Lunarof(int year, int month, int day) Creates a Lunar date (non-leap month) 创建农历日期(非闰月)static Lunarof(int year, int month, int day, boolean leapMonth) Creates a Lunar date 创建农历日期Converts to Chinese representation 转换为中文表示Converts to stem-branch representation 转换为干支表示toString()
-
Method Details
-
of
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
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
-
getHeavenlyStem
-
getEarthlyBranch
-
getStemBranchYear
Gets the stem-branch year name (干支纪年) 获取干支纪年- Returns:
- the stem-branch name | 干支名称
-
getChineseYear
Gets the full year representation in Chinese 获取完整的中文年份表示- Returns:
- the Chinese year | 中文年份
-
getChineseMonth
Gets the month name in Chinese 获取中文月份名称- Returns:
- the Chinese month | 中文月份
-
getChineseDay
-
toChinese
Converts to Chinese representation 转换为中文表示- Returns:
- the Chinese date string | 中文日期字符串
-
toStemBranch
Converts to stem-branch representation 转换为干支表示- Returns:
- the stem-branch date string | 干支日期字符串
-
compareTo
- Specified by:
compareToin interfaceComparable<Lunar>
-
equals
-
hashCode
-
toString
-