|
@@ -0,0 +1,43 @@
|
|
|
+package com.miaxis.test;
|
|
|
+
|
|
|
+import com.miaxis.common.utils.DateUtils;
|
|
|
+import com.nlf.calendar.Lunar;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+public class TestYear {
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ // 假设输入的是阳历日期
|
|
|
+ int year = 2023;
|
|
|
+ int month = 10; // 注意:月份从1开始,即1代表一月
|
|
|
+ int day = 30;
|
|
|
+
|
|
|
+ // 假设使用 cn.6tail 的 lunar 库来转换日期
|
|
|
+ Date d1 = DateUtils.parseDate("1988-11-23 17:51:00");
|
|
|
+
|
|
|
+ Lunar lunar = Lunar.fromDate(d1);
|
|
|
+
|
|
|
+
|
|
|
+ System.out.println("公历:"+lunar.getSolar().getYear()+","+lunar.getSolar().getMonth()+","+lunar.getSolar().getDay()+","+lunar.getSolar().getHour());
|
|
|
+
|
|
|
+ System.out.println("农历:"+lunar.getYear()+","+lunar.getMonth()+","+lunar.getDay()+","+lunar.getTime());
|
|
|
+
|
|
|
+ // 获取干支纪年
|
|
|
+ String ganYear = lunar.getYearGan();
|
|
|
+ String zhiYear = lunar.getYearZhi();
|
|
|
+
|
|
|
+ String ganMonth = lunar.getMonthGan();
|
|
|
+ String zhiMonth = lunar.getMonthZhi();
|
|
|
+
|
|
|
+ String ganDay = lunar.getDayGan();
|
|
|
+ String zhiDay = lunar.getDayZhi();
|
|
|
+
|
|
|
+ String timeGan = lunar.getTimeGan();
|
|
|
+ String timeZhi = lunar.getTimeZhi();
|
|
|
+
|
|
|
+
|
|
|
+ // 输出结果
|
|
|
+ System.out.println(ganYear+","+zhiYear+","+ganMonth+","+zhiMonth+","+ganDay+","+zhiDay+","+timeGan+","+timeZhi);
|
|
|
+ }
|
|
|
+}
|