1using System; 
  2   
  3namespace NetBee.Calendar
  4
  5    public class CNDate 
  6    
  7        private const ushort START_YEAR = 1901
  8        private const ushort END_YEAR = 2050
  9        private string[] ConstellationName = 
 10  
 11      "白羊座""金牛座""双子座"
 12      "巨蟹座""狮子座""处女座"
 13      "天秤座""天蝎座""射手座"
 14      "摩羯座""水瓶座""双鱼座"}

 15        private string[] LunarHolDayName = 
 16  
 17      "小寒""大寒""立春""雨水"
 18      "惊蛰""春分""清明""谷雨"
 19      "立夏""小满""芒种""夏至"
 20      "小暑""大暑""立秋""处暑"
 21      "白露""秋分""寒露""霜降"
 22      "立冬""小雪""大雪""冬至"}

 23   
 24        //数组gLunarDay存入阴历1901年到2100年每年中的月天数信息, 
 25        //阴历每月只能是29或30天,一年用12(或13)个二进制位表示,对应位为1表30天,否则为29天 
 26        private int[] gLunarMonthDay = 
 27                                           //测试数据只有1901.1.1 --2050.12.31 
 28                                           0x4ae00xa5700x52680xd2600xd9500x6aa80x56a00x9ad00x4ae80x4ae0//1910 
 29                                           0xa4d80xa4d00xd2500xd5480xb5500x56a00x96d00x95b00x49b80x49b0//1920 
 30                                           0xa4b00xb2580x6a500x6d400xada80x2b600x95700x49780x49700x64b0//1930 
 31                                           0xd4a00xea500x6d480x5ad00x2b600x93700x92e00xc9680xc9500xd4a0//1940 
 32                                           0xda500xb5500x56a00xaad80x25d00x92d00xc9580xa9500xb4a80x6ca0//1950 
 33                                           0xb5500x55a80x4da00xa5b00x52b80x52b00xa9500xe9500x6aa00xad50//1960 
 34                                           0xab500x4b600xa5700xa5700x52600xe9300xd9500x5aa80x56a00x96d0//1970 
 35                                           0x4ae80x4ad00xa4d00xd2680xd2500xd5280xb5400xb6a00x96d00x95b0//1980 
 36                                           0x49b00xa4b80xa4b00xb2580x6a500x6d400xada00xab600x93700x4978//1990 
 37                                           0x49700x64b00x6a500xea500x6b280x5ac00xab600x93680x92e00xc960//2000 
 38                                           0xd4a80xd4a00xda500x5aa80x56a00xaad80x25d00x92d00xc9580xa950//2010 
 39                                           0xb4a00xb5500xb5500x55a80x4ba00xa5b00x52b80x52b00xa9300x74a8//2020 
 40                                           0x6aa00xad500x4da80x4b600x95700xa4e00xd2600xe9300xd5300x5aa0//2030 
 41                                           0x6b500x96d00x4ae80x4ad00xa4d00xd2580xd2500xd5200xdaa00xb5a0//2040 
 42                                           0x56d00x4ad80x49b00xa4b80xa4b00xaa500xb5280x6d200xada00x55b0}
//2050 
 43   
 44        //数组gLanarMonth存放阴历1901年到2050年闰月的月份,如没有则为0,每字节存两年 
 45        byte[] gLunarMonth=
 46                               0x000x500x040x000x20//1910 
 47                               0x600x050x000x200x70//1920 
 48                               0x050x000x400x020x06//1930 
 49                               0x000x500x030x070x00//1940 
 50                               0x600x040x000x200x70//1950 
 51                               0x050x000x300x800x06//1960 
 52                               0x000x400x030x070x00//1970 
 53                               0x500x040x080x000x60//1980 
 54                               0x040x0a0x000x600x05//1990 
 55                               0x000x300x800x050x00//2000 
 56                               0x400x020x070x000x50//2010 
 57                               0x040x090x000x600x04//2020 
 58                               0x000x200x600x050x00//2030 
 59                               0x300xb00x060x000x50//2040 
 60                               0x020x070x000x500x03}
//2050 
 61   
 62        //数组gLanarHoliDay存放每年的二十四节气对应的阳历日期 
 63        //每年的二十四节气对应的阳历日期几乎固定,平均分布于十二个月中 
 64        // 1月 2月 3月 4月 5月 6月 
 65        //小寒 大寒 立春 雨水 惊蛰 春分 清明 谷雨 立夏 小满 芒种 夏至 
 66        // 7月 8月 9月 10月 11月 12月 
 67        //小暑 大暑 立秋 处暑 白露 秋分 寒露 霜降 立冬 小雪 大雪 冬至 
 68        //********************************************************************************* 
 69        // 节气无任何确定规律,所以只好存表,要节省空间,所以
 70        //**********************************************************************************} 
 71        //数据格式说明: 
 72        //如1901年的节气为 
 73        // 1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11月 12月 
 74        // 6, 21, 4, 19, 6, 21, 5, 21, 6,22, 6,22, 8, 23, 8, 24, 8, 24, 8, 24, 8, 23, 8, 22 
 75        // 9, 6, 11,4, 9, 6, 10,6, 9,7, 9,7, 7, 8, 7, 9, 7, 9, 7, 9, 7, 8, 7, 15 
 76        //上面第一行数据为每月节气对应日期,15减去每月第一个节气,每月第二个节气减去15得第二行 
 77        // 这样每月两个节气对应数据都小于16,每月用一个字节存放,高位存放第一个节气数据,低位存放 
 78        //第二个节气的数据,可得下表 
 79        byte[] gLunarHolDay=
 80                                0x960xB40x960xA60x970x970x780x790x790x690x780x77//1901 
 81                                0x960xA40x960x960x970x870x790x790x790x690x780x78//1902 
 82                                0x960xA50x870x960x870x870x790x690x690x690x780x78//1903 
 83                                0x860xA50x960xA50x960x970x880x780x780x790x780x87//1904 
 84                                0x960xB40x960xA60x970x970x780x790x790x690x780x77//1905 
 85                                0x960xA40x960x960x970x970x790x790x790x690x780x78//1906 
 86                                0x960xA50x870x960x870x870x790x690x690x690x780x78//1907 
 87                                0x860xA50x960xA50x960x970x880x780x780x690x780x87//1908 
 88                                0x960xB40x960xA60x970x970x780x790x790x690x780x77//1909 
 89                                0x960xA40x960x960x970x970x790x790x790x690x780x78//1910 
 90                                0x960xA50x870x960x870x870x790x690x690x690x780x78//1911 
 91                                0x860xA50x960xA50x960x970x880x780x780x690x780x87//1912 
 92                                0x950xB40x960xA60x970x970x780x790x790x690x780x77//1913 
 93                                0x960xB40x960xA60x970x970x790x790x790x690x780x78//1914 
 94                                0x960xA50x970x960x970x870x790x790x690x690x780x78//1915 
 95                                0x960xA50x960xA50x960x970x880x780x780x790x770x87//1916 
 96                                0x950xB40x960xA60x960x970x780x790x780x690x780x87//1917 
 97                                0x960xB40x960xA60x970x970x790x790x790x690x780x77//1918 
 98                                0x960xA50x970x960x970x870x790x790x690x690x780x78//1919 
 99                                0x960xA50x960xA50x960x970x880x780x780x790x770x87//1920 
100                                0x950xB40x960xA50x960x970x780x790x780x690x780x87//1921 
101                                0x960xB40x960xA60x970x970x790x790x790x690x780x77//1922 
102                                0x960xA40x960x960x970x870x790x790x690x690x780x78//1923 
103                                0x960xA50x960xA50x960x970x880x780x780x790x770x87//1924 
104                                0x950xB40x960xA50x960x970x780x790x780x690x780x87//1925 
105                                0x960xB40x960xA60x970x970x780x790x790x690x780x77//1926 
106                                0x960xA40x960x960x970x870x790x790x790x690x780x78//1927 
107                                0x960xA50x960xA50x960x960x880x780x780x780x870x87//1928 
108                                0x950xB40x960xA50x960x970x880x780x780x790x770x87//1929 
109                                0x960xB40x960xA60x970x970x780x790x790x690x780x77//1930 
110                                0x960xA40x960x960x970x870x790x790x790x690x780x78//1931 
111                                0x960xA50x960xA50x960x960x880x780x780x780x870x87//1932 
112                                0x950xB40x960xA50x960x970x880x780x780x690x780x87//1933 
113                                0x960xB40x960xA60x970x970x780x790x790x690x780x77//1934 
114                                0x960xA40x960x960x970x970x790x790x790x690x780x78//1935 
115                                0x960xA50x960xA50x960x960x880x780x780x780x870x87//1936 
116                                0x950xB40x960xA50x960x970x880x780x780x690x780x87//1937 
117                                0x960xB40x960xA60x970x970x780x790x790x690x780x77//1938 
118                                0x960xA40x960x960x970x970x790x790x790x690x780x78//1939 
119                                0x960xA50x960xA50x960x960x880x780x780x780x870x87//1940 
120                                0x950xB40x960xA50x960x970x880x780x780x690x780x87//1941 
121                                0x960xB40x960xA60x970x970x780x790x790x690x780x77//1942 
122                                0x960xA40x960x960x970x970x790x790x790x690x780x78//1943 
123                                0x960xA50x960xA50xA60x960x880x780x780x780x870x87//1944 
124                                0x950xB40x960xA50x960x970x880x780x780x790x770x87//1945 
125                                0x950xB40x960xA60x970x970x780x790x780x690x780x77//1946 
126                                0x960xB40x960xA60x970x970x790x790x790x690x780x78//1947 
127                                0x960xA50xA60xA50xA60x960x880x880x780x780x870x87//1948 
128                                0xA50xB40x960xA50x960x970x880x790x780x790x770x87//1949 
129                                0x950xB40x960xA50x960x970x780x790x780x690x780x77//1950 
130                                0x960xB40x960xA60x970x970x790x790x790x690x780x78//1951 
131                                0x960xA50xA60xA50xA60x960x880x880x780x780x870x87//1952 
132                                0xA50xB40x960xA50x960x970x880x780x780x790x770x87//1953 
133                                0x950xB40x960xA50x960x970x780x790x780x680x780x87//1954 
134                                0x960xB40x960xA60x970x970x780x790x790x690x780x77//1955 
135                                0x960xA50xA50xA50xA60x960x880x880x780x780x870x87//1956 
136                                0xA50xB40x960xA50x960x970x880x780x780x790x770x87//1957 
137                                0x950xB40x960xA50x960x970x880x780x780x690x780x87//1958 
138                                0x960xB40x960xA60x970x970x780x790x790x690x780x77//1959 
139                                0x960xA40xA50xA50xA60x960x880x880x880x780x870x87//1960 
140                                0xA50xB40x960xA50x960x960x880x780x780x780x870x87//1961 
141                                0x960xB40x960xA50x960x970x880x780x780x690x780x87//1962 
142                                0x960xB40x960xA60x970x970x780x790x790x690x780x77//1963 
143                                0x960xA40xA50xA50xA60x960x880x880x880x780x870x87//1964 
144                                0xA50xB40x960xA50x960x960x880x780x780x780x870x87//1965 
145                                0x950xB40x960xA50x960x970x880x780x780x690x780x87//1966 
146                                0x960xB40x960xA60x970x970x780x790x790x690x780x77//1967 
147                                0x960xA40xA50xA50xA60xA60x880x880x880x780x870x87//1968 
148                                0xA50xB40x960xA50x960x960x880x780x780x780x870x87//1969 
149                                0x950xB40x960xA50x960x970x880x780x780x690x780x87//1970 
150                                0x960xB40x960xA60x970x970x780x790x790x690x780x77//1971 
151                                0x960xA40xA50xA50xA60xA60x880x880x880x780x870x87//1972 
152                                0xA50xB50x960xA50xA60x960x880x780x780x780x870x87//1973 
153                                0x950xB40x960xA50x960x970x880x780x780x690x780x87//1974 
154                                0x960xB40x960xA60x970x970x780x790x780x690x780x77//1975 
155                                0x960xA40xA50xB50xA60xA60x880x890x880x780x870x87//1976 
156                                0xA50xB40x960xA50x960x960x880x880x780x780x870x87//1977 
157                                0x950xB40x960xA50x960x970x880x780x780x790x780x87//1978 
158                                0x960xB40x960xA60x960x970x780x790x780x690x780x77//1979 
159                                0x960xA40xA50xB50xA60xA60x880x880x880x780x870x87//1980 
160                                0xA50xB40x960xA50xA60x960x880x880x780x780x770x87//1981 
161                                0x950xB40x960xA50x960x970x880x780x780x790x770x87//1982 
162                                0x950xB40x960xA50x960x970x780x790x780x690x780x77//1983 
163                                0x960xB40xA50xB50xA60xA60x870x880x880x780x870x87//1984 
164                                0xA50xB40xA60xA50xA60x960x880x880x780x780x870x87//1985 
165                                0xA50xB40x960xA50x960x970x880x780x780x790x770x87//1986 
166                                0x950xB40x960xA50x960x970x880x790x780x690x780x87//1987 
167                                0x960xB40xA50xB50xA60xA60x870x880x880x780x870x86//1988 
168                                0xA50xB40xA50xA50xA60x960x880x880x880x780x870x87//1989 
169                                0xA50xB40x960xA50x960x960x880x780x780x790x770x87//1990 
170                                0x950xB40x960xA50x860x970x880x780x780x690x780x87//1991 
171                                0x960xB40xA50xB50xA60xA60x870x880x880x780x870x86//1992 
172                                0xA50xB30xA50xA50xA60x960x880x880x880x780x870x87//1993 
173                                0xA50xB40x960xA50x960x960x880x780x780x780x870x87//1994 
174                                0x950xB40x960xA50x960x970x880x760x780x690x780x87//1995 
175                                0x960xB40xA50xB50xA60xA60x870x880x880x780x870x86//1996 
176                                0xA50xB30xA50xA50xA60xA60x880x880x880x780x870x87//1997 
177                                0xA50xB40x960xA50x960x960x880x780x780x780x870x87//1998 
178                                0x950xB40x960xA50x960x970x880x780x780x690x780x87//1999 
179                                0x960xB40xA50xB50xA60xA60x870x880x880x780x870x86//2000 
180                                0xA50xB30xA50xA50xA60xA60x880x880x880x780x870x87//2001 
181                                0xA50xB40x960xA50x960x960x880x780x780x780x870x87//2002 
182                                0x950xB40x960xA50x960x970x880x780x780x690x780x87//2003 
183                                0x960xB40xA50xB50xA60xA60x870x880x880x780x870x86//2004 
184                                0xA50xB30xA50xA50xA60xA60x880x880x880x780x870x87//2005 
185                                0xA50xB40x960xA50xA60x960x880x880x780x780x870x87//2006 
186                                0x950xB40x960xA50x960x970x880x780x780x690x780x87//2007 
187                                0x960xB40xA50xB50xA60xA60x870x880x870x780x870x86//2008 
188                                0xA50xB30xA50xB50xA60xA60x880x880x880x780x870x87//2009 
189                                0xA50xB40x960xA50xA60x960x880x880x780x780x870x87//2010 
190                                0x950xB40x960xA50x960x970x880x780x780x790x780x87//2011 
191                                0x960xB40xA50xB50xA50xA60x870x880x870x780x870x86//2012 
192                                0xA50xB30xA50xB50xA60xA60x870x880x880x780x870x87//2013 
193                                0xA50xB40x960xA50xA60x960x880x880x780x780x870x87//2014 
194                                0x950xB40x960xA50x960x970x880x780x780x790x770x87//2015 
195                                0x950xB40xA50xB40xA50xA60x870x880x870x780x870x86//2016 
196                                0xA50xC30xA50xB50xA60xA60x870x880x880x780x870x87//2017 
197                                0xA50xB40xA60xA50xA60x960x880x880x780x780x870x87//2018 
198                                0xA50xB40x960xA50x960x960x880x780x780x790x770x87//2019 
199                                0x950xB40xA50xB40xA50xA60x970x870x870x780x870x86//2020 
200                                0xA50xC30xA50xB50xA60xA60x870x880x880x780x870x86//2021 
201                                0xA50xB40xA50xA50xA60x960x880x880x880x780x870x87//2022 
202                                0xA50xB40x960xA50x960x960x880x780x780x790x770x87//2023 
203                                0x950xB40xA50xB40xA50xA60x970x870x870x780x870x96//2024 
204                                0xA50xC30xA50xB50xA60xA60x870x880x880x780x870x86//2025 
205                                0xA50xB30xA50xA50xA60xA60x880x880x880x780x870x87//2026 
206                                0xA50xB40x960xA50x960x960x880x780x780x780x870x87//2027 
207                                0x950xB40xA50xB40xA50xA60x970x870x870x780x870x96//2028 
208                                0xA50xC30xA50xB50xA60xA60x870x880x880x780x870x86//2029 
209                                0xA50xB30xA50xA50xA60xA60x880x880x880x780x870x87//2030 
210                                0xA50xB40x960xA50x960x960x880x780x780x780x870x87//2031 
211                                0x950xB40xA50xB40xA50xA60x970x870x870x780x870x96//2032 
212                                0xA50xC30xA50xB50xA60xA60x880x880x880x780x870x86//2033 
213                                0xA50xB30xA50xA50xA60xA60x880x780x880x780x870x87//2034 
214                                0xA50xB40x960xA50xA60x960x880x880x780x780x870x87//2035 
215                                0x950xB40xA50xB40xA50xA60x970x870x870x780x870x96//2036 
216                                0xA50xC30xA50xB50xA60xA60x870x880x880x780x870x86//2037 
217                                0xA50xB30xA50xA50xA60xA60x880x880x880x780x870x87//2038 
218                                0xA50xB40x960xA50xA60x960x880x880x780x780x870x87//2039 
219                                0x950xB40xA50xB40xA50xA60x970x870x870x780x870x96//2040 
220                                0xA50xC30xA50xB50xA50xA60x870x880x870x780x870x86//2041 
221                                0xA50xB30xA50xB50xA60xA60x880x880x880x780x870x87//2042 
222                                0xA50xB40x960xA50xA60x960x880x880x780x780x870x87//2043 
223                                0x950xB40xA50xB40xA50xA60x970x870x870x880x870x96//2044 
224                                0xA50xC30xA50xB40xA50xA60x870x880x870x780x870x86//2045 
225                                0xA50xB30xA50xB50xA60xA60x870x880x880x780x870x87//2046 
226                                0xA50xB40x960xA50xA60x960x880x880x780x780x870x87//2047 
227                                0x950xB40xA50xB40xA50xA50x970x870x870x880x860x96//2048 
228                                0xA40xC30xA50xA50xA50xA60x970x870x870x780x870x86//2049 
229                                0xA50xC30xA50xB50xA60xA60x870x880x780x780x870x87}
//2050 
230   
231   
232        private DateTime m_Date; 
233        public DateTime Date 
234        
235            getreturn m_Date;} 
236            set{ m_Date = value;} 
237        }
 
238   
239        public CNDate() 
240        
241            Date = DateTime.Today; 
242        }
 
243        public CNDate(DateTime dt) 
244        
245            Date = dt.Date; // 2004/3/21
246        }
 
247        //计算指定日期的星座序号 
248        public int GetConstellation() 
249        
250            int Y, M, D; 
251            Y = m_Date.Year; 
252            M = m_Date.Month; 
253            D = m_Date.Day; 
254            Y = M * 100 + D; 
255            if (((Y >= 321&& (Y <= 419))) return 0;} 
256            else if ((Y >= 420&& (Y <= 520)) return 1;} 
257            else if ((Y >= 521&& (Y <= 620)) return 2;} 
258            else if ((Y >= 621&& (Y <= 722)) return 3;} 
259            else if ((Y >= 723&& (Y <= 822)) return 4;} 
260            else if ((Y >= 823&& (Y <= 922)) return 5;} 
261            else if ((Y >= 923&& (Y <= 1022)) return 6;} 
262            else if ((Y >= 1023&& (Y <= 1121)) return 7;} 
263            else if ((Y >= 1122&& (Y <= 1221)) return 8;} 
264            else if ((Y >= 1222|| (Y <= 119)) return 9;} 
265            else if ((Y >= 120&& (Y <= 218)) return 10;} 
266            else if ((Y >= 219&& (Y <= 320)) return 11;} 
267            else return -1;}
268        }
 
269   
270        //计算指定日期的星座名称 
271        public string GetConstellationName() 
272        
273            int Constellation; 
274            Constellation = GetConstellation(); 
275            if ((Constellation >= 0&& (Constellation <= 11)) 
276            return ConstellationName[Constellation];} 
277            else 
278            return "";}
279        }
 
280   
281        //计算公历当天对应的节气 0-23,-1表示不是节气 
282        public int l_GetLunarHolDay() 
283        
284            byte Flag; 
285            int Day, iYear, iMonth, iDay; 
286            iYear = m_Date.Year; 
287            if ((iYear < START_YEAR) || (iYear > END_YEAR)) 
288            return -1;}
289            iMonth = m_Date.Month; 
290            iDay = m_Date.Day; 
291            Flag = gLunarHolDay[(iYear - START_YEAR) * 12 + iMonth - 1]; 
292            if (iDay < 15
293            { Day = 15 - ((Flag >> 4& 0x0f);} 
294            else 
295            {Day = (Flag & 0x0f+ 15;}
296            if (iDay == Day) 
297            
298                if (iDay > 15
299                return (iMonth - 1* 2 + 1;} 
300                else 
301                return (iMonth - 1* 2;} 
302            }
 
303            else 
304            {return -1;}
305        }
 
306   
307        public string FormatMonth(ushort iMonth, bool bLunar) 
308        
309            string szText = "正二三四五六七八九十"
310            string strMonth; 
311            if ((!bLunar) && (iMonth == 1)) 
312            return "一月";} 
313            if (iMonth <= 10
314            
315                strMonth = ""
316                strMonth = strMonth + szText.Substring(iMonth - 11); 
317                strMonth = strMonth + ""
318                return strMonth; 
319            }
 
320            if (iMonth == 11
321            { strMonth = "十一";} 
322            else 
323            { strMonth = "十二";} 
324            return strMonth + ""
325        }
    
326   
327        public string FormatLunarDay(ushort iDay)  // 2004年3月出现问题 *
328        
329            string szText1 = "初十廿三"
330            string szText2 = "一二三四五六七八九十"
331            string strDay; 
332
333            if(iDay>30)return iDay.ToString();
334            
335            if ((iDay != 20&& (iDay != 30)) 
336            
337                strDay = szText1.Substring((iDay - 1/ 101); 
338                strDay = strDay + szText2.Substring((iDay - 1% 101); 
339            }
 
340            else 
341            
342                strDay = szText1.Substring((iDay / 10* 1 + 01); 
343                strDay = strDay + ""
344            }
 
345            return strDay; 
346        }
 
347   
348        public string GetLunarHolDay() // S1
349        
350            ushort iYear, iMonth, iDay; 
351            int i; 
352            TimeSpan ts; 
353            iYear = (ushort)(m_Date.Year); // 2004
354            if ((iYear < START_YEAR) || (iYear > END_YEAR)) 
355            return "";}
356            i = l_GetLunarHolDay();  // -1
357            if ((i >= 0&& (i <= 23)) 
358            return LunarHolDayName[i];} 
359            else 
360            
361                ts = m_Date - (new DateTime(START_YEAR, 11)); 
362                l_CalcLunarDate(out iYear, out iMonth, out iDay, (uint)(ts.Days)); 
363                return FormatMonth(iMonth, true+ FormatLunarDay(iDay); 
364            }
 
365        }
 
366   
367        //返回阴历iLunarYear年的闰月月份,如没有返回0 1901年1月---2050年12月 
368        public int GetLeapMonth(ushort iLunarYear) 
369        
370            byte Flag; 
371            //if ((iLunarYear < START_YEAR) || (iLunarYear > END_YEAR)) 
372            //{ return 0;}; 
373            Flag = gLunarMonth[(iLunarYear - START_YEAR) / 2]; 
374            if ((iLunarYear - START_YEAR) % 2 == 0
375            {return Flag >> 4;} 
376            else 
377            {return Flag & 0x0F;} 
378        }
 
379   
380        //返回阴历iLunarYer年阴历iLunarMonth月的天数,如果iLunarMonth为闰月, 
381        //高字为第二个iLunarMonth月的天数,否则高字为0 1901年1月---2050年12月 
382        public uint LunarMonthDays(ushort iLunarYear, ushort iLunarMonth) 
383        
384            int Height, Low; 
385            int iBit; 
386            //if ((iLunarYear < START_YEAR) || (iLunarYear > END_YEAR)) 
387            //{ return 30; } 
388            Height = 0
389            Low = 29
390            iBit = 16 - iLunarMonth; 
391            if ((iLunarMonth > GetLeapMonth(iLunarYear)) && (GetLeapMonth(iLunarYear) > 0)) 
392            {iBit--;} 
393            if ((gLunarMonthDay[iLunarYear - START_YEAR] & (1 << iBit)) > 0
394            {Low++;} 
395            if (iLunarMonth == GetLeapMonth(iLunarYear)) 
396            
397                if ((gLunarMonthDay[iLunarYear - START_YEAR] & (1 << (iBit-1)))>0
398                {Height = 30;} 
399                else 
400                {Height = 29;}
401            }
 
402            return (uint)((uint)(Low)|(uint)(Height)<<16); //合成为uint 
403        }
 
404   
405        //返回阴历iLunarYear年的总天数 1901年1月---2050年12月 
406        public int LunarYearDays(ushort iLunarYear) 
407        
408            int Days; 
409            uint tmp; 
410            if ((iLunarYear < START_YEAR) || (iLunarYear > END_YEAR)) 
411            return 0;}
412            Days = 0
413            for (ushort i=1; i <= 12; i++
414            
415                tmp = LunarMonthDays(iLunarYear, i); 
416                Days = Days + ((ushort)(tmp>>16& 0xFFFF); //取高位 
417                Days = Days + (ushort)(tmp); //取低位 
418            }
 
419            return Days; 
420        }
 
421   
422        //计算从1901年1月1日过iSpanDays天后的阴历日期 
423        public void l_CalcLunarDate(out ushort iYear, out ushort iMonth, out ushort iDay, uint iSpanDays) // S2
424        
425            uint tmp; 
426            //阳历1901年2月19日为阴历1901年正月初一 
427            //阳历1901年1月1日到2月19日共有49天 
428            if (iSpanDays < 49)  // Pass
429            
430                iYear = START_YEAR - 1
431                if (iSpanDays < 19
432                
433                    iMonth = 11
434                    iDay = (ushort)(11 + iSpanDays); 
435                }
 
436                else 
437                
438                    iMonth = 12
439                    iDay = (ushort)(iSpanDays - 18); 
440                }
 
441                return
442            }
 
443            //下面从阴历1901年正月初一算起 
444            iSpanDays = iSpanDays - 49
445            iYear = START_YEAR; 
446            iMonth = 1
447            iDay = 1
448            //计算年 
449            tmp = (uint)LunarYearDays(iYear); 
450            while (iSpanDays >= tmp) 
451            
452                iSpanDays = iSpanDays - tmp; 
453                iYear++
454                tmp = (uint)LunarYearDays(iYear); 
455            }
 
456            //计算月 
457            tmp = LunarMonthDays(iYear, iMonth); //取低位
458            while (iSpanDays >= tmp) 
459            
460                iSpanDays = iSpanDays - tmp;            
461                if (GetLeapMonth(iYear)==iMonth) 
462                
463                    tmp = (ushort)((LunarMonthDays(iYear, iMonth)>>16)&0xFFFF); //取高位 
464                    if (iSpanDays < tmp)break;
465                    iSpanDays = iSpanDays - tmp;
466                }

467                iMonth++;
468                tmp = (ushort)LunarMonthDays(iYear,iMonth); //取低位 * + short Modified <<<<<<
469            }
 
470            //计算日 
471            iDay = (ushort)(iDay + iSpanDays); 
472        }
 
473   
474   
475        //把iYear年格式化成天干记年法表示的字符串 
476        public string FormatLunarYear() 
477        
478            string strYear; 
479            string szText1 = "甲乙丙丁戊己庚辛壬癸"
480            string szText2 = "子丑寅卯辰巳午未申酉戌亥"
481            string szText3 = "鼠牛虎免龙蛇马羊猴鸡狗猪"
482            ushort iYear; 
483            iYear = (ushort)(m_Date.Year); 
484            strYear = szText1.Substring((iYear - 4% 101); 
485            strYear = strYear + szText2.Substring((iYear - 4% 121); 
486            strYear = strYear + " "
487            strYear = strYear + szText3.Substring((iYear - 4% 121); 
488            strYear = strYear + ""
489            return strYear; 
490        }
 
491    }
 //class CNDate 
492   
493    public class Test 
494    
495        static void Main(string[] args) 
496        
497            CNDate dt = new CNDate(DateTime.Today); 
498            Console.WriteLine("今天是:" + dt.Date.ToString() + dt.GetConstellationName()); 
499            Console.WriteLine(dt.l_GetLunarHolDay()); 
500            Console.WriteLine(dt.GetLunarHolDay()); 
501            Console.WriteLine("闰月" + dt.GetLeapMonth(UInt16.Parse(args[0]))); 
502            Console.WriteLine("2月的天数" + dt.LunarMonthDays(UInt16.Parse(args[0]), UInt16.Parse(args[1]))); 
503            Console.WriteLine("天数" + dt.LunarYearDays(UInt16.Parse(args[0]))); 
504            Console.WriteLine("" + dt.FormatLunarYear()); 
505            dt.Date = DateTime.Today.AddDays(1); 
506            Console.WriteLine("明天是:" + dt.Date.ToString() + dt.GetConstellationName()); 
507        }
 
508    }
 //class Test 
509}
Posted on 2005-05-21 22:17  RichardChoi  阅读(589)  评论(0)    收藏  举报