首先加入Maven依赖
<dependency> <groupId>cn.6tail</groupId> <artifactId>lunar</artifactId> <version>1.3.9</version> </dependency>
?示例代码:
public static void main(String[] args) {
// 实例化
Lunar lunar = Lunar.fromYmd(2023, 11, 8);
System.out.println(lunar); //农历 二〇二三年冬月初八
// 转阳历
Solar solar = lunar.getSolar();
System.out.println(solar.toString()); //阳历 2023-12-20
System.out.println(solar.toFullString()); //2023-12-20 00:00:00 星期三 射手座
Lunar d = Lunar.fromDate(new Date());
System.out.println(d);
System.out.println(d.toFullString());
System.out.println(d.getYear());
System.out.println(d.getMonth());
System.out.println(d.getDay());
System.out.println(d.getYearInChinese());
System.out.println(d.getMonthInChinese());
System.out.println(d.getDayInChinese());
}
效果图: