.net显示今天农历的代码
using System;
using System.Globalization;//
namespace Project.ChinaDate
{
///
/// 显示今天农历类
///
public
class CNDate
{
private DateTime m_Date; //今天的日期
private
readonly
int cny; //农历的年月日
private
int cnm; //农历的年月日
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
1 using System;
2 using System.Globalization;//
3
4 namespace Project.ChinaDate
5 {
6
7 ///
8 <summary>
9 /// 显示今天农历类
10 ///
11 </summary>
12
13
14 public
15 class CNDate
16 {
17 private DateTime m_Date; //今天的日期
18
19 private
20 readonly
21 int cny; //农历的年月日
22
23 private
24 int cnm; //农历的年月日
25
26 private
27 readonly
28 int cnd; //农历的年月日
29
30 private
31 readonly
32 int icnm; //农历闰月
33
34 ///
35 <summary>
36 /// 显示日期构造函数
37 ///
38 </summary>
39
40 public CNDate()
41 {
42 m_Date = DateTime.Today;
43 ChineseLunisolarCalendar cnCalendar =
44 new ChineseLunisolarCalendar();
45 cny = cnCalendar.GetSexagenaryYear(m_Date);
46 cnm = cnCalendar.GetMonth(m_Date);
47 cnd = cnCalendar.GetDayOfMonth(m_Date);
48 icnm = cnCalendar.GetLeapMonth(cnCalendar.GetYear(m_Date));
49 }
50 ///
51 <summary>
52 /// 返回格式化的公历显示
53 ///
54 </summary>
55 ///
56 <returns>格式如:2008年05月14日</returns>
57
58 public
59 string GetDate()
60 {
61 int y = m_Date.Year;
62 int m = m_Date.Month;
63 int d = m_Date.Day;
64 return String.Format("{0}年{1:00}月{2:00}日", y, m, d);
65 }
66 ///
67 <summary>
68 /// 返回格式化的星期显示
69 ///
70 </summary>
71 ///
72 <returns>格式如:星期日</returns>
73
74 public
75 string GetWeek()
76 {
77 string ws =
78 "星期";
79 int w = Convert.ToInt32(m_Date.DayOfWeek);
80 ws = ws +
81 "日一二三四五六".Substring(w, 1);
82 return ws;
83 }
84 ///
85 <summary>
86 /// 返回格式化的农历显示
87 ///
88 </summary>
89 ///
90 <returns>格式如:戊子(鼠)年润四月廿三</returns>
91
92 public
93 string GetCNDate()
94 {
95 string txcns =
96 "";
97 const
98 string szText1 =
99 "癸甲乙丙丁戊己庚辛壬";
100 const
101 string szText2 =
102 "亥子丑寅卯辰巳午未申酉戌";
103 const
104 string szText3 =
105 "猪鼠牛虎免龙蛇马羊猴鸡狗";
106 int tn = cny %
107 10; //天干
108
109 int dn = cny %
110 12; //地支
111 txcns += szText1.Substring(tn, 1);
112 txcns += szText2.Substring(dn, 1);
113 txcns +=
114 "("
115 + szText3.Substring(dn, 1) +
116 ")年";
117 //格式化月份显示
118
119 string[] cnMonth ={ "", "正月", "二月", "三月", "四月", "五月", "六月"
120 , "七月", "八月", "九月", "十月", "十一月", "十二月", "十二月" };
121 if (icnm >
122 0)
123 {
124 for (int i = icnm +
125 1; i <
126 13; i++) cnMonth = cnMonth[i -
127 1];
128 cnMonth[icnm] =
129 "闰"
130 + cnMonth[icnm];
131 }
132 txcns += cnMonth[cnm];
133 string[] cnDay ={ "", "初一", "初二", "初三", "初四", "初五", "初六", "初七"
134 , "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六"
135 , "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五"
136 , "廿六", "廿七", "廿八", "廿九", "三十" };
137 txcns += cnDay[cnd];
138 return txcns;
139 }
140 }