ChinaDate { public static Map<String, Integer> solarToLunar(int year, int month, int day) { Calendar calendar = Calendar.getInstance(); calendar.set(year, month - 1, day); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String dateStr = sdf.format(calendar.getTime()); String lunarStr = solarToLunar(dateStr, true); Map<String, Integer> map = new HashMap<>(); String[] lunarArray = lunarStr.split("-"); map.put("year", Integer.parseInt(lunarArray[0])); map.put("month", Integer.parseInt(lunarArray[1])); map.put("day", Integer.parseInt(lunarArray[2])); return map; }  static Map<String, Integer> lunarToSolar(int year, int month, int day); static String lunarToSolar(String lunarDate); static Map<String, Integer> solarToLunar(int year, int month, int day); static String solarToLunar(String solarDate, Boolean isFormat);  }
@Test public void solarToLunar() throws Exception { System.out.println("阳历转阴历: "); String origin1 = "1994-02-04"; String origin2 = "2015-12-04"; String expectLunarDate1 = "1993-12-24"; String result1 = ChinaDate.solarToLunar(origin1, true); String result2 = ChinaDate.solarToLunar(origin2, false); assertTrue(expectLunarDate1.equals(result1)); System.out.println("阳历：" + origin1 + " 转为 阴历：" + result1); System.out.println("阳历：" + origin2 + " 转为 " + result2); }