似水无痕

http://www.fushunboy.com, http://www.kunet.cn, http://www.gotdotnet.cn
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

用C#编写农历控件的源码

Posted on 2006-01-27 00:12  似水无痕  阅读(702)  评论(0编辑  收藏  举报
using System; 


namespace CNCalendar 



public class CNDate 



private const ushort START_YEAR = 1901

private const ushort END_YEAR = 2050

private string[] ConstellationName = 



"白羊座""金牛座""双子座"

"巨蟹座""狮子座""处女座"

"天秤座""天蝎座""射手座"

"摩羯座""水瓶座""双鱼座"}


private string[] LunarHolDayName = 



"小寒""大寒""立春""雨水"

"惊蛰""春分""清明""谷雨"

"立夏""小满""芒种""夏至"

"小暑""大暑""立秋""处暑"

"白露""秋分""寒露""霜降"

"立冬""小雪""大雪""冬至"}



//数组gLunarDay存入阴历1901年到2100年每年中的月天数信息, 

//阴历每月只能是29或30天,一年用12(或13)个二进制位表示,对应位为1表30天,否则为29天 

private int[] gLunarMonthDay = 

//测试数据只有1901.1.1 --2050.12.31 

0x4ae00xa5700x52680xd2600xd9500x6aa80x56a00x9ad00x4ae80x4ae0//1910 

0xa4d80xa4d00xd2500xd5480xb5500x56a00x96d00x95b00x49b80x49b0//1920 

0xa4b00xb2580x6a500x6d400xada80x2b600x95700x49780x49700x64b0//1930 

0xd4a00xea500x6d480x5ad00x2b600x93700x92e00xc9680xc9500xd4a0//1940 

0xda500xb5500x56a00xaad80x25d00x92d00xc9580xa9500xb4a80x6ca0//1950 

0xb5500x55a80x4da00xa5b00x52b80x52b00xa9500xe9500x6aa00xad50//1960 

0xab500x4b600xa5700xa5700x52600xe9300xd9500x5aa80x56a00x96d0//1970 

0x4ae80x4ad00xa4d00xd2680xd2500xd5280xb5400xb6a00x96d00x95b0//1980 

0x49b00xa4b80xa4b00xb2580x6a500x6d400xada00xab600x93700x4978//1990 

0x49700x64b00x6a500xea500x6b280x5ac00xab600x93680x92e00xc960//2000 

0xd4a80xd4a00xda500x5aa80x56a00xaad80x25d00x92d00xc9580xa950//2010 

0xb4a00xb5500xb5500x55a80x4ba00xa5b00x52b80x52b00xa9300x74a8//2020 

0x6aa00xad500x4da80x4b600x95700xa4e00xd2600xe9300xd5300x5aa0//2030 

0x6b500x96d00x4ae80x4ad00xa4d00xd2580xd2500xd5200xdaa00xb5a0//2040 

0x56d00x4ad80x49b00xa4b80xa4b00xaa500xb5280x6d200xada00x55b0}
//2050 


//数组gLanarMonth存放阴历1901年到2050年闰月的月份,如没有则为0,每字节存两年 

byte[] gLunarMonth=

0x000x500x040x000x20//1910 

0x600x050x000x200x70//1920 

0x050x000x400x020x06//1930 

0x000x500x030x070x00//1940 

0x600x040x000x200x70//1950 

0x050x000x300x800x06//1960 

0x000x400x030x070x00//1970 

0x500x040x080x000x60//1980 

0x040x0a0x000x600x05//1990 

0x000x300x800x050x00//2000 

0x400x020x070x000x50//2010 

0x040x090x000x600x04//2020 

0x000x200x600x050x00//2030 

0x300xb00x060x000x50//2040 

0x020x070x000x500x03}
//2050 


//数组gLanarHoliDay存放每年的二十四节气对应的阳历日期 

//每年的二十四节气对应的阳历日期几乎固定,平均分布于十二个月中 

// 1月 2月 3月 4月 5月 6月 

//小寒 大寒 立春 雨水 惊蛰 春分 清明 谷雨 立夏 小满 芒种 夏至 

// 7月 8月 9月 10月 11月 12月 

//小暑 大暑 立秋 处暑 白露 秋分 寒露 霜降 立冬 小雪 大雪 冬至 

//********************************************************************************* 

// 节气无任何确定规律,所以只好存表,要节省空间,所以

//**********************************************************************************} 

//数据格式说明: 

//如1901年的节气为 

// 1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11月 12月 

// 6, 21, 4, 19, 6, 21, 5, 21, 6,22, 6,22, 8, 23, 8, 24, 8, 24, 8, 24, 8, 23, 8, 22 

// 9, 6, 11,4, 9, 6, 10,6, 9,7, 9,7, 7, 8, 7, 9, 7, 9, 7, 9, 7, 8, 7, 15 

//上面第一行数据为每月节气对应日期,15减去每月第一个节气,每月第二个节气减去15得第二行 

// 这样每月两个节气对应数据都小于16,每月用一个字节存放,高位存放第一个节气数据,低位存放 

//第二个节气的数据,可得下表 

byte[] gLunarHolDay=

0x960xB40x960xA60x970x970x780x790x790x690x780x77//1901 

0x960xA40x960x960x970x870x790x790x790x690x780x78//1902 

0x960xA50x870x960x870x870x790x690x690x690x780x78//1903 

0x860xA50x960xA50x960x970x880x780x780x790x780x87//1904 

0x960xB40x960xA60x970x970x780x790x790x690x780x77//1905 

0x960xA40x960x960x970x970x790x790x790x690x780x78//1906 

0x960xA50x870x960x870x870x790x690x690x690x780x78//1907 

0x860xA50x960xA50x960x970x880x780x780x690x780x87//1908 

0x960xB40x960xA60x970x970x780x790x790x690x780x77//1909 

0x960xA40x960x960x970x970x790x790x790x690x780x78//1910 

0x960xA50x870x960x870x870x790x690x690x690x780x78//1911 

0x860xA50x960xA50x960x970x880x780x780x690x780x87//1912 

0x950xB40x960xA60x970x970x780x790x790x690x780x77//1913 

0x960xB40x960xA60x970x970x790x790x790x690x780x78//1914 

0x960xA50x970x960x970x870x790x790x690x690x780x78//1915 

0x960xA50x960xA50x960x970x880x780x780x790x770x87//1916 

0x950xB40x960xA60x960x970x780x790x780x690x780x87//1917 

0x960xB40x960xA60x970x970x790x790x790x690x780x77//1918 

0x960xA50x970x960x970x870x790x790x690x690x780x78//1919 

0x960xA50x960xA50x960x970x880x780x780x790x770x87//1920 

0x950xB40x960xA50x960x970x780x790x780x690x780x87//1921 

0x960xB40x960xA60x970x970x790x790x790x690x780x77//1922 

0x960xA40x960x960x970x870x790x790x690x690x780x78//1923 

0x960xA50x960xA50x960x970x880x780x780x790x770x87//1924 

0x950xB40x960xA50x960x970x780x790x780x690x780x87//1925 

0x960xB40x960xA60x970x970x780x790x790x690x780x77//1926 

0x960xA40x960x960x970x870x790x790x790x690x780x78//1927 

0x960xA50x960xA50x960x960x880x780x780x780x870x87//1928 

0x950xB40x960xA50x960x970x880x780x780x790x770x87//1929 

0x960xB40x960xA60x970x970x780x790x790x690x780x77//1930 

0x960xA40x960x960x970x870x790x790x790x690x780x78//1931 

0x960xA50x960xA50x960x960x880x780x780x780x870x87//1932 

0x950xB40x960xA50x960x970x880x780x780x690x780x87//1933 

0x960xB40x960xA60x970x970x780x790x790x690x780x77//1934 

0x960xA40x960x960x970x970x790x790x790x690x780x78//1935 

0x960xA50x960xA50x960x960x880x780x780x780x870x87//1936 

0x950xB40x960xA50x960x970x880x780x780x690x780x87//1937 

0x960xB40x960xA60x970x970x780x790x790x690x780x77//1938 

0x960xA40x960x960x970x970x790x790x790x690x780x78//1939 

0x960xA50x960xA50x960x960x880x780x780x780x870x87//1940 

0x950xB40x960xA50x960x970x880x780x780x690x780x87//1941 

0x960xB40x960xA60x970x970x780x790x790x690x780x77//1942 

0x960xA40x960x960x970x970x790x790x790x690x780x78//1943 

0x960xA50x960xA50xA60x960x880x780x780x780x870x87//1944 

0x950xB40x960xA50x960x970x880x780x780x790x770x87//1945 

0x950xB40x960xA60x970x970x780x790x780x690x780x77//1946 

0x960xB40x960xA60x970x970x790x790x790x690x780x78//1947 

0x960xA50xA60xA50xA60x960x880x880x780x780x870x87//1948 

0xA50xB40x960xA50x960x970x880x790x780x790x770x87//1949 

0x950xB40x960xA50x960x970x780x790x780x690x780x77//1950 

0x960xB40x960xA60x970x970x790x790x790x690x780x78//1951 

0x960xA50xA60xA50xA60x960x880x880x780x780x870x87//1952 

0xA50xB40x960xA50x960x970x880x780x780x790x770x87//1953 

0x950xB40x960xA50x960x970x780x790x780x680x780x87//1954 

0x960xB40x960xA60x970x970x780x790x790x690x780x77//1955 

0x960xA50xA50xA50xA60x960x880x880x780x780x870x87//1956 

0xA50xB40x960xA50x960x970x880x780x780x790x770x87//1957 

0x950xB40x960xA50x960x970x880x780x780x690x780x87//1958 

0x960xB40x960xA60x970x970x780x790x790x690x780x77//1959 

0x960xA40xA50xA50xA60x960x880x880x880x780x870x87//1960 

0xA50xB40x960xA50x960x960x880x780x780x780x870x87//1961 

0x960xB40x960xA50x960x970x880x780x780x690x780x87//1962 

0x960xB40x960xA60x970x970x780x790x790x690x780x77//1963 

0x960xA40xA50xA50xA60x960x880x880x880x780x870x87//1964 

0xA50xB40x960xA50x960x960x880x780x780x780x870x87//1965 

0x950xB40x960xA50x960x970x880x780x780x690x780x87//1966 

0x960xB40x960xA60x970x970x780x790x790x690x780x77//1967 

0x960xA40xA50xA50xA60xA60x880x880x880x780x870x87//1968 

0xA50xB40x960xA50x960x960x880x780x780x780x870x87//1969 

0x950xB40x960xA50x960x970x880x780x780x690x780x87//1970 

0x960xB40x960xA60x970x970x780x790x790x690x780x77//1971 

0x960xA40xA50xA50xA60xA60x880x880x880x780x870x87//1972 

0xA50xB50x960xA50xA60x960x880x780x780x780x870x87//1973 

0x950xB40x960xA50x960x970x880x780x780x690x780x87//1974 

0x960xB40x960xA60x970x970x780x790x780x690x780x77//1975 

0x960xA40xA50xB50xA60xA60x880x890x880x780x870x87//1976 

0xA50xB40x960xA50x960x960x880x880x780x780x870x87//1977 

0x950xB40x960xA50x960x970x880x780x780x790x780x87//1978 

0x960xB40x960xA60x960x970x780x790x780x690x780x77//1979 

0x960xA40xA50xB50xA60xA60x880x880x880x780x870x87//1980 

0xA50xB40x960xA50xA60x960x880x880x780x780x770x87//1981 

0x950xB40x960xA50x960x970x880x780x780x790x770x87//1982 

0x950xB40x960xA50x960x970x780x790x780x690x780x77//1983 

0x960xB40xA50xB50xA60xA60x870x880x880x780x870x87//1984 

0xA50xB40xA60xA50xA60x960x880x880x780x780x870x87//1985 

0xA50xB40x960xA50x960x970x880x780x780x790x770x87//1986 

0x950xB40x960xA50x960x970x880x790x780x690x780x87//1987 

0x960xB40xA50xB50xA60xA60x870x880x880x780x870x86//1988 

0xA50xB40xA50xA50xA60x960x880x880x880x780x870x87//1989 

0xA50xB40x960xA50x960x960x880x780x780x790x770x87//1990 

0x950xB40x960xA50x860x970x880x780x780x690x780x87//1991 

0x960xB40xA50xB50xA60xA60x870x880x880x780x870x86//1992 

0xA50xB30xA50xA50xA60x960x880x880x880x780x870x87//1993 

0xA50xB40x960xA50x960x960x880x780x780x780x870x87//1994 

0x950xB40x960xA50x960x970x880x760x780x690x780x87//1995 

0x960xB40xA50xB50xA60xA60x870x880x880x780x870x86//1996 

0xA50xB30xA50xA50xA60xA60x880x880x880x780x870x87//1997 

0xA50xB40x960xA50x960x960x880x780x780x780x870x87//1998 

0x950xB40x960xA50x960x970x880x780x780x690x780x87//1999 

0x960xB40xA50xB50xA60xA60x870x880x880x780x870x86//2000 

0xA50xB30xA50xA50xA60xA60x880x880x880x780x870x87//2001 

0xA50xB40x960xA50x960x960x880x780x780x780x870x87//2002 

0x950xB40x960xA50x960x970x880x780x780x690x780x87//2003 

0x960xB40xA50xB50xA60xA60x870x880x880x780x870x86//2004 

0xA50xB30xA50xA50xA60xA60x880x880x880x780x870x87//2005 

0xA50xB40x960xA50xA60x960x880x880x780x780x870x87//2006 

0x950xB40x960xA50x960x970x880x780x780x690x780x87//2007 

0x960xB40xA50xB50xA60xA60x870x880x870x780x870x86//2008 

0xA50xB30xA50xB50xA60xA60x880x880x880x780x870x87//2009 

0xA50xB40x960xA50xA60x960x880x880x780x780x870x87//2010 

0x950xB40x960xA50x960x970x880x780x780x790x780x87//2011 

0x960xB40xA50xB50xA50xA60x870x880x870x780x870x86//2012 

0xA50xB30xA50xB50xA60xA60x870x880x880x780x870x87//2013 

0xA50xB40x960xA50xA60x960x880x880x780x780x870x87//2014 

0x950xB40x960xA50x960x970x880x780x780x790x770x87//2015 

0x950xB40xA50xB40xA50xA60x870x880x870x780x870x86//2016 

0xA50xC30xA50xB50xA60xA60x870x880x880x780x870x87//2017 

0xA50xB40xA60xA50xA60x960x880x880x780x780x870x87//2018 

0xA50xB40x960xA50x960x960x880x780x780x790x770x87//2019 

0x950xB40xA50xB40xA50xA60x970x870x870x780x870x86//2020 

0xA50xC30xA50xB50xA60xA60x870x880x880x780x870x86//2021 

0xA50xB40xA50xA50xA60x960x880x880x880x780x870x87//2022 

0xA50xB40x960xA50x960x960x880x780x780x790x770x87//2023 

0x950xB40xA50xB40xA50xA60x970x870x870x780x870x96//2024 

0xA50xC30xA50xB50xA60xA60x870x880x880x780x870x86//2025 

0xA50xB30xA50xA50xA60xA60x880x880x880x780x870x87//2026 

0xA50xB40x960xA50x960x960x880x780x780x780x870x87//2027 

0x950xB40xA50xB40xA50xA60x970x870x870x780x870x96//2028 

0xA50xC30xA50xB50xA60xA60x870x880x880x780x870x86//2029 

0xA50xB30xA50xA50xA60xA60x880x880x880x780x870x87//2030 

0xA50xB40x960xA50x960x960x880x780x780x780x870x87//2031 

0x950xB40xA50xB40xA50xA60x970x870x870x780x870x96//2032 

0xA50xC30xA50xB50xA60xA60x880x880x880x780x870x86//2033 

0xA50xB30xA50xA50xA60xA60x880x780x880x780x870x87//2034 

0xA50xB40x960xA50xA60x960x880x880x780x780x870x87//2035 

0x950xB40xA50xB40xA50xA60x970x870x870x780x870x96//2036 

0xA50xC30xA50xB50xA60xA60x870x880x880x780x870x86//2037 

0xA50xB30xA50xA50xA60xA60x880x880x880x780x870x87//2038 

0xA50xB40x960xA50xA60x960x880x880x780x780x870x87//2039 

0x950xB40xA50xB40xA50xA60x970x870x870x780x870x96//2040 

0xA50xC30xA50xB50xA50xA60x870x880x870x780x870x86//2041 

0xA50xB30xA50xB50xA60xA60x880x880x880x780x870x87//2042 

0xA50xB40x960xA50xA60x960x880x880x780x780x870x87//2043 

0x950xB40xA50xB40xA50xA60x970x870x870x880x870x96//2044 

0xA50xC30xA50xB40xA50xA60x870x880x870x780x870x86//2045 

0xA50xB30xA50xB50xA60xA60x870x880x880x780x870x87//2046 

0xA50xB40x960xA50xA60x960x880x880x780x780x870x87//2047 

0x950xB40xA50xB40xA50xA50x970x870x870x880x860x96//2048 

0xA40xC30xA50xA50xA50xA60x970x870x870x780x870x86//2049 

0xA50xC30xA50xB50xA60xA60x870x880x780x780x870x87}
//2050 



private DateTime m_Date; 

public DateTime Date 



getreturn m_Date;} 

set{ m_Date = value;} 

}
 


public CNDate() 



Date 
= DateTime.Today; 

}
 

public CNDate(DateTime dt) 



Date 
= dt.Date; 

}
 

//计算指定日期的星座序号 

public int GetConstellation() 



int Y, M, D; 

= m_Date.Year; 

= m_Date.Month; 

= m_Date.Day; 

= M * 100 + D; 

if (((Y >= 321&& (Y <= 419))) return 0;} 

else if ((Y >= 420&& (Y <= 520)) return 1;} 

else if ((Y >= 521&& (Y <= 620)) return 2;} 

else if ((Y >= 621&& (Y <= 722)) return 3;} 

else if ((Y >= 723&& (Y <= 822)) return 4;} 

else if ((Y >= 823&& (Y <= 922)) return 5;} 

else if ((Y >= 923&& (Y <= 1022)) return 6;} 

else if ((Y >= 1023&& (Y <= 1121)) return 7;} 

else if ((Y >= 1122&& (Y <= 1221)) return 8;} 

else if ((Y >= 1222|| (Y <= 119)) return 9;} 

else if ((Y >= 120&& (Y <= 218)) return 10;} 

else if ((Y >= 219&& (Y <= 320)) return 11;} 

else return -1;}

}
 


//计算指定日期的星座名称 

public string GetConstellationName() 



int Constellation; 

Constellation 
= GetConstellation(); 

if ((Constellation >= 0&& (Constellation <= 11)) 

return ConstellationName[Constellation];} 

else 

return "";}

}
 


//计算公历当天对应的节气 0-23,-1表示不是节气 

public int l_GetLunarHolDay() 



byte Flag; 

int Day, iYear, iMonth, iDay; 

iYear 
= m_Date.Year; 

if ((iYear < START_YEAR) || (iYear > END_YEAR)) 

return -1;}

iMonth 
= m_Date.Month; 

iDay 
= m_Date.Day; 

Flag 
= gLunarHolDay[(iYear - START_YEAR) * 12 + iMonth - 1]; 

if (iDay < 15

{ Day = 15 - ((Flag >> 4& 0x0f);} 

else 

{Day = (Flag & 0x0f+ 15;}

if (iDay == Day) 



if (iDay > 15

return (iMonth - 1* 2 + 1;} 

else 

return (iMonth - 1* 2;} 

}
 

else 

{return -1;}

}
 


public string FormatMonth(ushort iMonth, bool bLunar) 



string szText = "正二三四五六七八九十"

string strMonth; 

if ((!bLunar) && (iMonth == 1)) 

return "一月";} 

if (iMonth <= 10



strMonth 
= ""

strMonth 
= strMonth + szText.Substring(iMonth - 11); 

strMonth 
= strMonth + ""

return strMonth; 

}
 

if (iMonth == 11

{ strMonth = "十一";} 

else 

{ strMonth = "十二";} 

return strMonth + ""

}
 



public string FormatLunarDay(ushort iDay) 



string szText1 = "初十廿三"

string szText2 = "一二三四五六七八九十"

string strDay; 

if ((iDay != 20&& (iDay != 30)) 



strDay 
= szText1.Substring((iDay - 1/ 101); 

strDay 
= strDay + szText2.Substring((iDay - 1% 101); 

}
 

else 



strDay 
= szText1.Substring((iDay / 10* 2 + 12); 

strDay 
= strDay + ""

}
 

return strDay; 

}
 


public string GetLunarHolDay() 



ushort iYear, iMonth, iDay; 

int i; 

TimeSpan ts; 

iYear 
= (ushort)(m_Date.Year); 

if ((iYear < START_YEAR) || (iYear > END_YEAR)) 

return "";}

= l_GetLunarHolDay(); 

if ((i >= 0&& (i <= 23)) 

return LunarHolDayName[i];} 

else 



ts 
= m_Date - (new DateTime(START_YEAR, 11)); 

l_CalcLunarDate(
out iYear, out iMonth, out iDay, (uint)(ts.Days)); 

return FormatMonth(iMonth, true+ FormatLunarDay(iDay); 

}
 

}
 


//返回阴历iLunarYear年的闰月月份,如没有返回0 1901年1月---2050年12月 

public int GetLeapMonth(ushort iLunarYear) 



byte Flag; 

if ((iLunarYear < START_YEAR) || (iLunarYear > END_YEAR)) 

return 0;}

Flag 
= gLunarMonth[(iLunarYear - START_YEAR) / 2]; 

if ((iLunarYear - START_YEAR) % 2 == 0

{return Flag >> 4;} 

else 

{return Flag & 0x0F;} 

}
 


//返回阴历iLunarYer年阴历iLunarMonth月的天数,如果iLunarMonth为闰月, 

//高字为第二个iLunarMonth月的天数,否则高字为0 1901年1月---2050年12月 

public uint LunarMonthDays(ushort iLunarYear, ushort iLunarMonth) 



int Height, Low; 

int iBit; 

if ((iLunarYear < START_YEAR) || (iLunarYear > END_YEAR)) 

return 30; } 

Height 
= 0

Low 
= 29

iBit 
= 16 - iLunarMonth; 

if ((iLunarMonth > GetLeapMonth(iLunarYear)) && (GetLeapMonth(iLunarYear) > 0)) 

{iBit--;} 

if ((gLunarMonthDay[iLunarYear - START_YEAR] & (1 << iBit)) > 0

{Low++;} 

if (iLunarMonth == GetLeapMonth(iLunarYear)) 



if ((gLunarMonthDay[iLunarYear - START_YEAR] & (1 << (iBit-1)))>0

{Height = 30;} 

else 

{Height = 29;} 

}
 

return (uint)((uint)(Low)|(uint)(Height)<<16); //合成为uint 

}
 


//返回阴历iLunarYear年的总天数 1901年1月---2050年12月 

public int LunarYearDays(ushort iLunarYear) 



int Days; 

uint tmp; 

if ((iLunarYear < START_YEAR) || (iLunarYear > END_YEAR)) 

return 0;}

Days 
= 0

for (ushort i=1; i <= 12; i++



tmp 
= LunarMonthDays(iLunarYear, i); 

Days 
= Days + ((ushort)(tmp>>16& 0xFFFF); //取高位 

Days 
= Days + (ushort)(tmp); //取低位 

}
 

return Days; 

}
 


//计算从1901年1月1日过iSpanDays天后的阴历日期 

public void l_CalcLunarDate(out ushort iYear, out ushort iMonth, out ushort iDay, uint iSpanDays) 



uint tmp; 

//阳历1901年2月19日为阴历1901年正月初一 

//阳历1901年1月1日到2月19日共有49天 

if (iSpanDays < 49



iYear 
= START_YEAR - 1

if (iSpanDays < 19



iMonth 
= 11

iDay 
= (ushort)(11 + iSpanDays); 

}
 

else 



iMonth 
= 12

iDay 
= (ushort)(iSpanDays - 18); 

}
 

return

}
 

//下面从阴历1901年正月初一算起 

iSpanDays 
= iSpanDays - 49

iYear 
= START_YEAR; 

iMonth 
= 1

iDay 
= 1

//计算年 

tmp 
= (uint)LunarYearDays(iYear); 

while (iSpanDays >= tmp) 



iSpanDays 
= iSpanDays - tmp; 

iYear
++

tmp 
= (uint)LunarYearDays(iYear); 

}
 

//计算月 

tmp 
= LunarMonthDays(iYear, iMonth); //取低位 

while (iSpanDays >= tmp) 



iSpanDays 
= iSpanDays - tmp; 

if (iMonth == GetLeapMonth(iYear)) 



tmp 
= (LunarMonthDays(iYear, iMonth)>>16)&0xFFFF//取高位 

if (iSpanDays < tmp) 

{break;} 

iSpanDays 
= iSpanDays - tmp; 

}
 

iMonth
++

tmp 
= LunarMonthDays(iYear,iMonth); //取低位 

}
 

//计算日 

iDay 
= (ushort)(iDay + iSpanDays); 

}
 



//把iYear年格式化成天干记年法表示的字符串 

public string FormatLunarYear() 



string strYear; 

string szText1 = "甲乙丙丁戊己庚辛壬癸"

string szText2 = "子丑寅卯辰巳午未申酉戌亥"

string szText3 = "鼠牛虎免龙蛇马羊猴鸡狗猪"

ushort iYear; 

iYear 
= (ushort)(m_Date.Year); 

strYear 
= szText1.Substring((iYear - 4% 101); 

strYear 
= strYear + szText2.Substring((iYear - 4% 121); 

strYear 
= strYear + " "

strYear 
= strYear + szText3.Substring((iYear - 4% 121); 

strYear 
= strYear + ""

return strYear; 

}
 

}
 //class CNDate 


public class Test 



static void Main(string[] args) 



CNDate dt 
= new CNDate(DateTime.Today); 

Console.WriteLine(
"今天是:" + dt.Date.ToString() + dt.GetConstellationName()); 

Console.WriteLine(dt.l_GetLunarHolDay()); 

Console.WriteLine(dt.GetLunarHolDay()); 

Console.WriteLine(
"闰月" + dt.GetLeapMonth(UInt16.Parse(args[0]))); 

Console.WriteLine(
"2月的天数" + dt.LunarMonthDays(UInt16.Parse(args[0]), UInt16.Parse(args[1]))); 

Console.WriteLine(
"天数" + dt.LunarYearDays(UInt16.Parse(args[0]))); 

Console.WriteLine(
"" + dt.FormatLunarYear()); 

dt.Date 
= DateTime.Today.AddDays(1); 

Console.WriteLine(
"明天是:" + dt.Date.ToString() + dt.GetConstellationName()); 
}
 
}
 //class Test 
}