.NET 公历转农历

公历转农历得使用农历闰年闰月对照表

好在.NET已经预备了这个对照表,我们不用再去声明,可以直接使用

public string ChineseLunisolarDate(DateTime ADataTime) { var clc = new System.Globalization.ChineseLunisolarCalendar(); var year = clc.GetYear(ADataTime); var month = clc.GetMonth(ADataTime); var day = clc.GetDayOfMonth(ADataTime); var leapMonth = clc.GetLeapMonth(year); return string.Format("{0}{1} {2}年{3}{4}月{5}{6}" , "甲乙丙丁戊己庚辛壬癸"[(year - 4) % 10] , "子丑寅卯辰巳午未申酉戌亥"[(year - 4) % 12] , "鼠牛虎兔龙蛇马羊猴鸡狗猪"[(year - 4) % 12] , month == leapMonth ? "润" : "" , "无正二三四五六七八九十冬腊"[leapMonth > 0 && leapMonth <= month ? month - 1 : month] , "初十廿三"[day / 10] , "日一二三四五六七八九"[day % 10] ); } private void Form1_Load(object sender, EventArgs e) { dateTimePicker1_ValueChanged(dateTimePicker1, EventArgs.Empty); } private void dateTimePicker1_ValueChanged(object sender, EventArgs e) { textBox1.Text = ChineseLunisolarDate(((DateTimePicker)sender).Value); } //System.Globalization.EastAsianLunisolarCalendar //System.Globalization.TaiwanLunisolarCalendar //System.Globalization.ThaiBuddhistCalendar //System.Globalization.KoreanLunisolarCalendar //System.Globalization.JapaneseLunisolarCalendar //System.Globalization.HebrewCalendar //System.Globalization.HijriCalendar //System.Globalization.JapaneseCalendar

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值