Explorar el Código

顺序练习出错修改

小么熊🐻 hace 1 año
padre
commit
d962cb4fee
Se han modificado 2 ficheros con 51 adiciones y 0 borrados
  1. 43 0
      nbjk-admin/src/test/java/com/miaxis/test/TestYear.java
  2. 8 0
      nbjk-common/pom.xml

+ 43 - 0
nbjk-admin/src/test/java/com/miaxis/test/TestYear.java

@@ -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);
+    }
+}

+ 8 - 0
nbjk-common/pom.xml

@@ -279,6 +279,14 @@
             <version>2.5.0</version>
         </dependency>
 
+
+        <dependency>
+            <groupId>cn.6tail</groupId>
+            <artifactId>lunar</artifactId>
+            <version>1.2.28</version>
+        </dependency>
+
+
     </dependencies>
 
 </project>