1 /// <summary>
2 /// 农历日历
3 /// </summary>
4 private static ChineseLunisolarCalendar calendar = new ChineseLunisolarCalendar();
5 /// <summary>
6 /// 中文数字
7 /// </summary>
8 private static string ChineseNumber = "〇一二三四五六七八九";
9 /// <summary>
10 /// 甲子
11 /// </summary>
12 public const string CelestialStem = "甲乙丙丁戊己庚辛壬癸";
13 /// <summary>
14 /// 阴历年干支
15 /// </summary>
16 public const string TerrestrialBranch = "子丑寅卯辰巳午未申酉戌亥";
17 /// <summary>
18 /// 属相
19 /// </summary>
20 public const string ShuXiang = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
21
22 /// <summary>
23 /// 甲子记年法
24 /// </summary>
25 /// <param name="time"></param>
26 /// <returns></returns>
27 public static string GetStemBranch(DateTime time)
28 {
29 string stemBranch = string.Empty;
30 int sexagenaryYear = calendar.GetSexagenaryYear(time);//与指定日期对应的甲子(60 年)循环中的年
31 if (sexagenaryYear % 10 == 0 && sexagenaryYear % 12 == 0)
32 {
33 stemBranch = CelestialStem.Substring(sexagenaryYear % 10+9, 1) + TerrestrialBranch.Substring(sexagenaryYear % 12 +11, 1);
34 }
35 else if (sexagenaryYear % 10 != 0 && sexagenaryYear % 12 == 0)
36 {
37 stemBranch = CelestialStem.Substring(sexagenaryYear % 10 - 1, 1) + TerrestrialBranch.Substring(sexagenaryYear % 12 +11, 1);
38 }
39 else if (sexagenaryYear % 10 == 0 && sexagenaryYear % 12 != 0)
40 {
41 stemBranch = CelestialStem.Substring(sexagenaryYear % 10+9, 1) + TerrestrialBranch.Substring(sexagenaryYear % 12 -1, 1);
42 }
43 else
44 {
45 stemBranch = CelestialStem.Substring(sexagenaryYear % 10 - 1, 1) + TerrestrialBranch.Substring(sexagenaryYear % 12 - 1, 1);
46 }
47 return stemBranch;
48 }
49 /// <summary>
50 /// 生肖
51 /// </summary>
52 /// <param name="time"></param>
53 /// <returns></returns>
54 public static string GetSX(DateTime time)
55 {
56 string SX = string.Empty;
57 int sexagenaryYear = calendar.GetSexagenaryYear(time);//与指定日期对应的甲子(60 年)循环中的年
58 if (sexagenaryYear % 12 == 0)
59 {
60 SX = ShuXiang.Substring(sexagenaryYear % 12 + 11, 1);
61 }
62 else
63 {
64 SX = ShuXiang.Substring(sexagenaryYear % 12 - 1, 1);
65 }
66 return SX;
67 }
68 /// <summary>
69 ///
70 /// </summary>
71 public GZForm()
72 {
73 InitializeComponent();
74 }
75 /// <summary>
76 ///
77 /// </summary>
78 /// <param name="sender"></param>
79 /// <param name="e"></param>
80 private void GZForm_Load(object sender, EventArgs e)
81 {
82 this.label1.Text = "农历今天是:" + GetStemBranch(DateTime.Now) + "年";
83 this.label2.Text = "农历今生肖是:" + GetSX(DateTime.Now);
84 }
85 /// <summary>
86 ///
87 /// </summary>
88 /// <param name="sender"></param>
89 /// <param name="e"></param>
90 private void button1_Click(object sender, EventArgs e)
91 {
92 this.label1.Text = "农历是:" + GetStemBranch(this.dateTimePicker1.Value) + "年";
93 this.label2.Text = "生肖是:" + GetSX(this.dateTimePicker1.Value);
94 }
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)成功.---Geovin Du(涂聚文)