Package com. zzst. cbfImpl. util;
Import java. text. ParseException;
Import java. text. SimpleDateFormat;
Import java. util. Calendar;
Import java. util. Date;
Public class NoLi {
Private int year;
Private int month;
Private int day;
Private boolean leap;
Final static String chineseNumber [] = {"1", "2", "3", "4", "5", "6", "7", "8 ", "9", "10", "11", "12 "};
Static SimpleDateFormat chineseDateFormat = new SimpleDateFormat ("MM dd, yyyy ");
Final static long [] lunarInfo = new long []
{0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2,
0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977,
0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970,
0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950,
0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557,
0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950, 0x06aa0,
0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0,
0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6,
0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570,
0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0,
0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5,
0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930,
0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530,
0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45,
0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0 };
// =======Return the total number of days of the lunar y year
Final private static int yearDays (int y ){
Int I, sum = 348;
For (I = 0x8000; I> 0x8; I >>= 1 ){
If (lunarInfo [y-1900] & I )! = 0) sum + = 1;
}
Return (sum + leapDays (y ));
}
// =======Return the number of days in the month of the y-year month of the lunar calendar
Final private static int leapDays (int y ){
If (leapMonth (y )! = 0 ){
If (lunarInfo [y-1900] & 0x10000 )! = 0)
Return 30;
Else
Return 29;
} Else
Return 0;
}
// =========Which Month 1-12 is sent back to the y-year lunar calendar, and 0 is returned if no value is returned.
Final private static int leapMonth (int y ){
Return (int) (lunarInfo [y-1900] & 0xf );
}
// =======Return the total number of days of the lunar month y
Final private static int monthDays (int y, int m ){
If (lunarinfo [Y-1900] & (0x10000> m) = 0)
Return 29;
Else
Return 30;
}
// =======Return the Chinese zodiac of the lunar y year
Final Public String animalsyear (){
Final string [] animals = new string [] {"rat", "Ox", "Tiger", "rabbit", "dragon", "snake", "horse ", "goat", "monkey", "chicken", "dog", "Swine "};
Return animals [(year-4) % 12];
}
// ======== The offset of the input month and day is returned to the primary branch, 0 = a child
Final Private Static string javasicalm (INT num ){
Final String [] Gan = new String [] {"A", "B", "C", "ding", "E", "Ji", "Geng ", "Xin", "shen", "Xi "};
Final String [] Zhi = new String [] {"sub", "ugly", "Yin", "Mao", "Chen", "Si", "Wu ", "wei", "shen", "you", "wei", "Hai "};
Return (Gan [num % 10] + Zhi [num % 12]);
}
// ======== Input offset to return a dry branch, 0 = a child
Final public String semantic ical (){
Int num = year-1900 + 36;
Return (cyclicalm (num ));
}
/**
* The Lunar Calendar corresponding to y, m, and D.
* YearCyl3: What is the difference between 1864 and over the years?
* MonCyl4: Number of leap months since January 31, 1900
* DayCyl5: the number of days different from that in December January 31, 1900, plus 40?
*
* @ Param cal
* @ Return
*/
Public NoLi (Calendar cal ){
Int yearCyl, monCyl, dayCyl;
Int leapMonth = 0;
Date baseDate = null;
Try {
BaseDate = chineseDateFormat. parse ("January 31, 1900 ");
} Catch (ParseException e ){
E. printStackTrace (); // To change body of catch statement use Options | File Templates.
}
// Find the number of days that are different from that in January 1, January 31, 1900.
Int offset = (int) (cal. getTime (). getTime ()-baseDate. getTime ()/86400000L );
DayCyl = offset + 40;
MonCyl = 14;
// Use offset to subtract the number of days per calendar year
// Calculate the day of the lunar calendar
// I. The final result is the year of the lunar calendar.
// Offset is the day of the year
Int iYear, daysOfYear = 0;
For (iYear = 1900; iYear <2050 & offset> 0; iYear ++ ){
Daysofyear = yeardays (iyear );
Offset-= daysofyear;
Moncyl + = 12;
}
If (offset <0 ){
Offset + = daysofyear;
Iyear --;
Moncyl-= 12;
}
// Lunar year
Year = iyear;
Yearcyl = iyear-1864;
LeapMonth = leapMonth (iYear); // which month is used, 1-12
Leap = false;
// Offset by the number of days in the current year, minus the number of days in each month (lunar calendar), and obtain the number of days in the current month.
Int iMonth, daysOfMonth = 0;
For (iMonth = 1; iMonth <13 & offset> 0; iMonth ++ ){
// Leap month
If (leapMonth> 0 & iMonth = (leapMonth + 1 )&&! Leap ){
-- IMonth;
Leap = true;
DaysOfMonth = leapDays (year );
} Else
DaysOfMonth = monthDays (year, iMonth );
Offset-= daysOfMonth;
// Release the leap month
If (leap & iMonth = (leapMonth + 1) leap = false;
If (! Leap) monCyl ++;
}
// When the offset value is 0 and the calculated month is a leap month, it must be corrected.
If (offset = 0 & leapMonth> 0 & iMonth = leapMonth + 1 ){
If (LEAP ){
Leap = false;
} Else {
Leap = true;
-- Imonth;
-- Moncyl;
}
}
// When offset is less than 0, correction is also required.
If (offset <0 ){
Offset + = daysofmonth;
-- Imonth;
-- Moncyl;
}
Month = Imonth;
Day = offset + 1;
}
Public static string getchinadaystring (INT day ){
String chineseten [] = {"", "10", "Shanghai", "Shanghai "};
Int n = day % 10 = 0? 9: day % 10-1;
If (day> 30)
Return "";
If (Day = 10)
Return "10th ";
Else
Return chineseten [day/10] + chinesenumber [N];
}
Public String tostring (){
Return year + "year" + (leap? "Week": "") + chinesenumber [month-1] + "month" + getchinadaystring (day );
}
Public static void main (string [] ARGs ){
Calendar cfirststarttime = calendar. getinstance ();
NoLi a = new NoLi (cFirstStartTime );
System. out. println (a. toString ());
}
}