C#公历转农历的简单方法
2013-06-09 11:52
211 查看
/// <summary> /// 公历转为农历的函数 /// </summary> /// <param name="solarDateTime">公历日期</param> /// <returns>农历的日期</returns> static string SolarToChineseLunisolarDate(DateTime solarDateTime) { System.Globalization.ChineseLunisolarCalendar cal = new System.Globalization.ChineseLunisolarCalendar(); int year = cal.GetYear(solarDateTime); int month = cal.GetMonth(solarDateTime); int day = cal.GetDayOfMonth(solarDateTime); int leapMonth = cal.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] ); } 使用的方法非常简单: string 农历 = SolarToChineseLunisolarDate(DateTime.Today);
相关文章推荐
- C#(ASP.NET)公历转农历的简单方法
- ASP.NET实现公历转农历的简单方法
- ASP.NET实现公历转农历的简单方法
- ASP.NET实现公历转农历的简单方法
- C# 遍历CheckBox的三种简单方法
- 用Java简单实现C#的参数为Action<T> Function<T,boolean>扩展方法
- C# 一个图片上传的简单方法
- C#简单生成随机密码的方法示例
- 简单干净的C#方法设计案例:SFCUI.AjaxValue()之二
- C#将Unicode编码转换为汉字字符串的简单方法
- C#中深拷贝对象的简单方法
- c# 计算时间间隔的简单方法(推荐)
- C#圆角窗体简单实现方法
- 一个简单方法完成C#时间间隔的计算
- 一个简单方法完成C#时间间隔的计算
- C#简单获取屏幕鼠标坐标点颜色方法介绍
- C#操作DateTable导入到Excel简单方法
- (简单)C#导出Excel表格的方法
- 一个很简单的C#例子,给网友解答的,总觉得应该有更简单的方法
- c#学习 10/22 字符串的各种方法与继承的简单介绍