chineseMonths[] 字符數組,每年 2 字節(16 位),高 4 位存閏月月份,低 12 位存 12 月大小(1=大月30天,0=小月29天)。bigLeapMonthYears[] 記錄 30 天閏月的年份索引。sectionalTermMap/Year、principleTermMap/Year 二維表,結合年份模 4 週期快速定節氣日期。ChineseCalendarGB cal = new ChineseCalendarGB();
cal.setGregorian(2024, 5, 18); // 設公曆日期
cal.computeChineseFields(); // 算農曆年月日
cal.computeSolarTerms(); // 算節氣
System.out.println(cal.toString()); // 輸出完整資訊
chineseYear:農曆年(如 4721)chineseMonth:農曆月(負數表示閏月,如 -4 為閏四月)chineseDate:農曆日sectionalTerm:節氣(如 5=立夏)principleTerm:中氣(如 21=小滿)(chineseYear-1)%10 天干,%12 地支,生肖同地支調用 getYearTable() 可獲得 58 行文本表格,含公曆/農曆對照、節氣標註、農曆月初標記。格式示例(2000 年 1 月):
一月 日 一 二 三 四 五 六 1/25 2/26 3/27 4/28 5/29 立春 臘月 8/ 2 9/ 3 10/ 4 11/ 5 12/ 6 13/ 7 14/ 8 15/ 9 16/10 17/11 18/12 19/13 20/14 雨水 22/16 23/17 24/18 25/19 26/20 27/21 28/22 29/23 30/24 31/25
說明:1/25 = 公曆 1 日 / 農曆 25 日;立春、雨水 為節氣;臘月 為農曆 12 月初一。
sectionalTermNames[]、principleTermNames[] 可本地化。computeChineseFields() 結果,或預生成 200 年查表數組 O(1) 查詢。源碼已開源於 CSDN(jeensung,2006),經無數項目驗證,是 Java 端農曆計算的經典參考實現。