/ * * This is the second Java program after my "HelloWorld", the function is the lunar rigor, the logic is simple, the key is that the data is not easy, thank Wangfei@engineer.com.cn and I I have been extracted from the foreigner; * There are some bugs in the program, so if you find it, please tell the younger brother zzymmm_ren@hotmail.com; if you want to reference or other needs, please indicate the data of wangfei@engineer.com.cn I don't have to mention it. Thank you; * The naming rules are the lunar calendar with GETL, and the columns start with GETS * /
/ ********************************************************* **** ****************************************** /
/ * * Created on 2005-1-13 * * Todo this Program is buy for Changing Lunar Calendar and Solar Calendar * * / package rwin.trans_calendar;
/ ** * @Author irwin zhou * * Todo this class offers the date data mainly * * / public class calendar {
// Array lIntLunarDay is stored in the monthly day information in every year from 1901 to 2100 of the lunar calendar, // The lunar calendar can only be 29 or 30 days every month, express with 12 (or 13) pieces of binary bit in One Year, // IT IS 30 Days for 1 Form in The Corresponding Location, OtherWise It Is 29 Days Private Static Final Int [] ilunarmonthdayStable =
{0x4ae0, 0xa570, 0x5268, 0xd260, 0xd950, 0x6aa8, 0x56a0, 0x9ad0, 0x4ae8, 0x4ae0, // 1910 0xa4d8, 0xa4d0, 0xd250, 0xd548, 0xb550, 0x56a0, 0x96d0, 0x95b0, 0x49b8, 0x49b0, // 1920 0xa4b0, 0xb258 , 0x6a50, 0x6d40, 0xada8, 0x2b60, 0x9570, 0x4978, 0x4970, 0x64b0, // 1930 0xd4a0, 0xea50, 0x6d48, 0x5ad0, 0x2b60, 0x9370, 0x92e0, 0xc968, 0xc950, 0xd4a0, // 1940 0xda50, 0xb550, 0x56a0, 0xaad8 , 0x25d0, 0x92d0, 0xc958, 0xa950, 0xb4a8, 0x6ca0, // 1950 0xb550, 0x55a8, 0x4da0, 0xa5b0, 0x52b8, 0x52b0, 0xa950, 0xe950, 0x6aa0, 0xad50, // 1960 0xab50, 0x4b60, 0xa570, 0xa570, 0x5260, 0xe930 , 0xd950, 0x5aa8, 0x56a0, 0x96d0, // 1970 0x4ae8, 0x4ad0, 0xa4d0, 0xd268, 0xd250, 0xd528, 0xb540, 0xb6a0, 0x96d0, 0x95b0, // 1980 0x49b0, 0xa4b8, 0xa4b0, 0xb258, 0x6a50, 0x6d40, 0xada0, 0xab60 , 0x9370, 0x4970, 0x64b0, 0x6a50, 0x1a50, 0x6b28, 0x5ac0, 0xAb60, 0x9368, 0x92e0, 0xc960, // 2000 0xD4A8, 0XD4A0, 0X56A0, 0X5AA8, 0x56A0, 0XAAD8, 0x25D0 , 0x92d0, 0xc958, 0xa950, // 2010 0xb4a0, 0xb550, 0xb550, 0x55a8, 0x4ba0, 0xa5b0, 0x52b8, 0x52b0, 0xa930, 0x74a8, // 2020 0x6aa0, 0xad50, 0x4da8, 0x4b60, 0x9570, 0xa4e0, 0xd260, 0xe930, 0xd530 , 0x5aa0, // 2030 0x6b50, 0x96d0, 0x4ae8, 0x4ad0, 0xa4d0, 0xd258, 0xd250, 0xd520, 0xdaa0, 0xb5a0, // 2040 0x56d0, 0x4ad8, 0x49b0, 0xa4b8, 0xa4b0, 0xaa50, 0xb528, 0x6d20, 0xada0, 0x55b0 // 2050}; // Array iLunarLeapMonthTable preserves the lunar calendar leap month from 1901 to 2050, // if it is 0 express not to have, every byte was stored for two years private static final char [] iLunarLeapMonthTable =
{0x00, 0x50, 0x04, 0x00, 0x20, // 1910 0x60, 0x05, 0x00, 0x20, 0x70, // 1920 0x05, 0x00, 0x40 0x02, 0x06, // 1930 0x00, 0x50, 0x03, 0x07, 0x00, // 1940 0x60, 0x04, 0x00, 0x20, 0x70, // 1950 0x05, 0x00, 0x30 0x80, 0x06, // 1960 0x00, 0x40, 0x03, 0x07, 0x00, // 1970 0x50, 0x04, 0x08, 0x00, 0x60, // 1980 0x04, 0x0a, 0x00, 0x60, 0x05, // 1990 0x00, 0x30, 0x80 0x05, 0x00, // 2000 0x40, 0x02, 0x07, 0x00, 0x50, // 2010 0x04, 0x09, 0x00, 0x60, 0x04, // 2020 0x00, 0x20, 0x60, 0x05, 0x00, // 2030 0x30, 0x50, // 2040 0x02, 0x07, 0x00, 0x50, 0x03 // 2050}; // array Isolarlunartable Stored The Offset Days // in New Year of Solar Calendar and Lunar Calendar from 1901 to 2050; Private Static Final Char [] isolarunaroffsettable = {49, 38, 28, 46, 34, 24, 43, 32, 21, 40, // 1910 29, 48, 36, 25, 44, 34, 22, 41, 31, 50, // 1920 38, 27, 46, 35, 23, 43, 32, 22, 40, 29, // 1930 47 , 36, 25, 44, 34, 23, 41, 30, 49, 38, // 1940 26, 45, 35, 24, 43, 32, 21, 40, 28, 47, // 1950 36, 26, 44, 33, 23, 42, 30, 48, 38, 27, // 1960 45, 35, 24, 43, 32, 20, 39, 29, 47, 36, // 1970 26, 45, 33, 22, 41, 30, 48, 37, 27, 46, // 1980 35, 24, 43, 32, 50, 39, 28, 47, 36, 26, // 1990 45, 34, 22, 40, 30, 49, 37, 27, 46, 35, // 2000 23, 42, 31, 21, 39, 28, 48, 37, 25, 44, // 2010 33, 23, 41, 31, 50, 39, 28, 47, 35, 24, // 2020 42, 30, 21, 40, 28, 47, 36, 25, 43, 33, // 2030 22, 41, 30, 49, 37, 26, 44, 33, 23, 42, // 2040 31, 21, 40, 29, 47, 36, 25, 44, 32, 22, // 2050};
Static Boolean BissolarleApyear (INT IYear) {Return ((iYear% 4 == 0) && (IYear% 100! = 0) || Iyear% 400 == 0);} // The days in the Month of Solar Calendar Static Int IgetsyearMonthdays (int Iyear, intimonth) {if (IMONTH == 1) || (iMonth == 3) || (iMonth == 5) || (iMonth == 7) || (iMonth == 8) | | (IMONTH == 10) || (IMONTH == 12)) Return 31; Else IF ((IMONTH == 4) || (IMONTH == 6) || (IMONTH == 9) || (IMONTH == 11)) RETURN 30; Else IF (iMonth == 2) {IF (BissolarleApyear (Iyear)) Return 29; Else Return 28;} else return 0;} // the offset days from new year and the day when point out in solar calendar static int iGetSNewYearOffsetDays (int iYear, int iMonth, int iDay) {int iOffsetDays = 0; for (int i = 1; i
ILAPMONTH)) IMONTH ; IF ((IlunarmontHdayStable [IlunarmontHdayStable [Iyear - 1901] & (0x8000 >> (IMONTH - 1))) == 0) Return 29; Else Return 30;} // Days in this year of lunar Calendar Static int getlyeardays (int IYear) {INT IYARDAYS = 0; int henticiapmonth = IgetLleapmonth (IYEAR); for (int i = 1; i <13; i ) iYearDays = IgetlmontHDAYS (IyleAr, i); if (ileapmonth> 0) Iyeardays = iGetLMonthDays (iYear, iLeapMonth 12); return iYearDays;} static int iGetLNewYearOffsetDays (int iYear, int iMonth, int iDay) {int iOffsetDays = 0; int iLeapMonth = iGetLLeapMonth (iYear); if ((iLeapMonth> 0) && (iLeapMonth == IMONTH - 12)) {imth = ileapmonth; IoffsetDays = IgetlmontHDAYS (IYear, IMONTH);} for (int i = 1; i // The solar calendar is turned into the lunar calendar static String sCalendarSolarToLundar (int iYear, int iMonth, int iDay) {int iLDay, iLMonth, iLYear; int iOffsetDays = iGetSNewYearOffsetDays (iYear, iMonth, iDay); int iLeapMonth = iGetLLeapMonth (iYear ); if (iOffsetDays iSolarLunarOffsetTable [iYear - 1901]; int iYearDays = bIsSolarLeapYear (iYear) 366:? 365; if (iOffsetDays> = iYearDays) {iSYear = iYear 1; iOffsetDays - = iYearDays;} else {iSYear = iYear;} iSDay = iOffsetDays 1; for (iSMonth = 1; iOffsetDays> = 0; iSMonth ) {iSDay = iOffsetDays 1; iOffsetDays - = iGetSYearMonthDays (iSYear, iSMonth);} iSMonth--; return "" iSYear (iSMonth> 9 iSMonth ? ":" 0 " ismonth) (isday> 9? Isday ": "0" isday);}} / ******************* ****************** This is file week.java ********************************* ************* / / * * Created on 2005-1-13 * * Todo this Program is buy for Changing Lunar Calendar and Solar Calendar * * / package rwin.trans_calendar; / ** * @Author irwin.zhou * * / public class week {int tent IWeek; Private string Sweek [] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "SATURDAY"} Public week () {iWeek = 0;} Public Week (INT W) {IF ((W> 6) || (W <0)) {System.out.Println ("Week out of Range, I think you want sunday); this.iweek = 0;} Else this.iweek = W;} public string toString () {return sweek [iWeek];}} / **************************************************** ***** ****************************************** / / * * Created on 2005-1-13 * * Todo this Program is buy for Changing Lunar Calendar and Solar Calendar * * / package rwin.trans_calendar; / ** * @Author irwin.zhou * * / public class mydate { Public int yiear; public int iMonth; private static int checkyear (INT IYEAR) {IF (IYear> 1901) && (Iyear <2050)) Return Iyear; else {system.out.println ("The year Out) Of Range, I Think You Want 1981 "); Return 1981;}} public mydate (int iodiear, intimonth, int iday) {this.iear = Checkyear (Iyear); this.Imonth = IMONTH; this.IDAY = iDay; } Public mydate (int iodieear = checkyear (iodiear); this.Imonth = IMONTH; this.IDAY = 1;} public mydate (int iodiear) {this.iyear = checkyear (IYAR); this .imonth = 1; this.iday = 1;} public mydate () {this.iyear = 1981; this.imonth = 1; this.iday = 1;} public string toString () {return "" this.iyear (this.imonth> 9? "" this.imonth: "0" this.imonth) (this.iday> 9? "" this.iday: "0" this.iday);} public boilean equals (MyDate MD) {return ((md.iday == this.iday) && (md.imonth == this.imonth) && (md.iyear == this.iyear);}} / ****** ******************************* TH Is is fas solardate.java ************************************************ / / * * Created on 2005-1-13 * * Todo this Program is buy for Changing Lunar Calendar and Solar Calendar * * / package rwin.trans_calendar; / ** * @author Irwin.Zhou * * TODO Realize some functions of the solar calendar * * / public class SolarDate extends MyDate {private static int checkMonth (int iMonth) {if (iMonth> 12) {System.out.println ( "Month Out of Range, I Think You Want 12 :)"); Return 12;} else IF (IMONTH <1) {System.out.Println ("Month Out of Range, I Think You Want 1 :)"); return 1;} else return iMonth;} private static int checkDay (int iYear, int iMonth, int iDay) {int iMonthDays = Calendar.iGetSYearMonthDays (iYear, iMonth); if (iDay> iMonthDays) {System.out.println ( " Day Out of Range, I Think You Want " IMONTHDAYS " :) "); Return IMONTHDAYS;} else if (iDay <1) {system.out.println (" Day Out of Range, I think you want 1 :) ");} Else return iDay;} public solardate (int iod) {super (Iyear); this.imonth = Checkmonth (IMONTH); this.iDay = checkday (this.iyear, this .imonth, iDay); Public solardate (int iodage) {super (iyear); this.imonth = Checkmonth (IMONTH); Public solardate (int iod) {super (iodie); Public solardate () {super ();} public string toString () {return "" this.iyear (this.imonth> 9? "-" this.imonth: "-0" this.imonth) ( THIS.IDAY> 9? "-" this.IDAY: "-0" this.iday); Public week toteek () {int = 1901; I / * * Created on 2005-1-13 * * Todo this Program is buy for Changing Lunar Calendar and Solar Calendar * * / package rwin.trans_calendar; / ** * @Author irwin.zhou * * Todo realize some functions of the lunar calendar * * / public class lunardate extends mydate { Private string schinesenum [] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" }; Private static int checkmonth (INT IYEAR, INT IMONTH) {IF (IMONTH> 12) && (iMonth == Calendar.iGetLleapmonth 12)) {Return IMONTH;} else if (IMONTH> 12) {System .out.println ("Month Out of Range, I Think You Want 12 :)"); Return 12; Else IF (IMONTH <1) {System.out.Println ("Month Out of Range, I think You Want 1 :) "); return 1;} else return iMonth;} private static int checkDay (int iYear, int iMonth, int iDay) {int iMonthDays = Calendar.iGetLMonthDays (iYear, iMonth); if (iDay> iMonthDays) {System. Out.println ("Day Out of Range, I Think You Want" IMONTHDAYS ":)"); Return IMONTHDAYS;} else if (iDay <1) {system.out.println ("Day Out of Range, I think You Want 1 :) "); Return 1;} else return iDay;} public lunardate (int iodage) {super (Iyear); this.imonth = Checkmonth (this.iyear, IMONTH); this. iDay = Checkday (this.iyear, this. IMONTH, IDAY;} public lunardate (int iodardate) {super (iodar); this.iyear, IMONTH);} public lunardate (int iodardate) {super (ieear);} public Lunardate () {SUPER ();} public string toString () {string scalendar = "Lunar"; Scalendar = SCHINESENUM [IYEAR / 1000] SCHINESENUM [IYear% 1000/100] SCHINESENUM [IYear% 100/10] SCHINESENUM [IYear% 10] "( tochinesera () ") year "; if (IMONTH> 12) {IMONTH - = 12; scalendar =" "; } If (iMonth == 12) scalendar = "twilies"; Else if (IMONTH == 11) Scalendar = "winter moon"; Else if (iMonth == 1) scalendar = "正 月"; Else Scalendar = SchineseNum [IMONTH] "Month"; if (iDay> 29) Scalendar = "Thirty"; Else IF (iDay> 20) Scalendar = "Twenty" SchineseUM [iDay% 20]; else if (iDay = = 20) Scalendar = "twenty"; Else if (iDay> 10) Scalendar = "10" SchineseNum [iDay% 10]; Else Scalendar = "First" Schinesenum [iDay]; returnis scalendar;} CnWeek toWeek () {int iOffsetDays = 0; for (int i = 1901; i public SolarDate toSolarDate () {int iYear, iMonth, iDay, iDate; SolarDate sd; iDate = Integer.parseInt (Calendar.sCalendarLundarToSolar (this.iYear, this.iMonth, this.iDay)); iYear = iDate / 10000; iMonth = iDate% 10000/100; IDAY = iDate% 100; sd = new solardate (Iyear, IMONTH, IDAY); return sd;}} Class cnWeek Extends Week {private string scnweek [] = {"Japan", "One", "Second", "Three", "Four", "Five", "Six"}; PUBLIC CNWEEK () {Super (); } Public cnweek {super (iWeek);} public string toString () {return "Week" scNweek [this.iweek];}