/// <summary>
/// 将 农历(阴历) 转换为 公历(阳历,西历)
/// 如果传入的参数中的年份是润年,需要另外进行加上润月的天数,简单测试,但没有做过多的测试,不知是否完全正确
///
/// DateTime dt = Convert.ToDateTime("2010-05-21 00:00:00");
/// MessageBox.Show(calendarChineseLunisolarToSolar(dt).ToString());
///
/// </summary>
///
public static DateTime calendarChineseLunisolarToSolar(DateTime ChineseLunisolarDateTime)
{
System.Globalization.ChineseLunisolarCalendar cal = new System.Globalization.ChineseLunisolarCalendar();
if (ChineseLunisolarDateTime.Year < 1902 || ChineseLunisolarDateTime.Year > 2100)
throw new Exception("只支持1902~2100期间的农历年");
DateTime dt = cal.ToDateTime(ChineseLunisolarDateTime.Year, ChineseLunisolarDateTime.Month, ChineseLunisolarDateTime.Day, 0, 0, 0, 0);
//检测是否含有润月
int leapMonth = cal.GetLeapMonth(ChineseLunisolarDateTime.Year);
int leapMonthInDays = 0;
if (leapMonth > 0)
{
//有润月,则读到这个润月里面的天数
leapMonthInDays = cal.GetDaysInMonth(ChineseLunisolarDateTime.Year, ChineseLunisolarDateTime.Month);
}
dt = dt.AddDays(leapMonthInDays);
return dt;
}
/// <summary>
/// 将公历(阳历,西历) 转换为 农历(阴历)
///
/// DateTime dt = Convert.ToDateTime("2010-07-2 00:00:00");
/// MessageBox.Show(calendarSolarToChineseLunisolar(dt).ToString());
///
/// </summary>
///
public static DateTime calendarSolarToChineseLunisolar(DateTime SolarDateTime)
{
System.Globalization.ChineseLunisolarCalendar cal = new System.Globalization.ChineseLunisolarCalendar();
int cYear = cal.GetYear(SolarDateTime);
int cMonth = cal.GetMonth(SolarDateTime);
int cDay = cal.GetDayOfMonth(SolarDateTime);
DateTime dt = Convert.ToDateTime(
Convert.ToString(cYear) + "-" +
Convert.ToString(cMonth) + "-" +
Convert.ToString(cDay)
+ " 00:00:00");
return dt;
}
c#农历转公历以及公历转农历
4星 · 超过85%的资源 需积分: 50 151 浏览量
2011-11-17
18:24:35
上传
评论 4
收藏 879B RAR 举报
saiko
- 粉丝: 2
- 资源: 5
最新资源
- 基于Matlab人脸肤色定理的教师人数统计+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab霍夫曼变换的表盘读数识别+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab火灾烟雾检测源码带GUI界面+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab的恶劣天气交通标志识别系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于MATLAB的霍夫曼变换的表盘示数识别+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab的车道线识别系统 +源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于MATLAB的教室人数统计系统带Gui界面+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于MATLAB的教室人数统计系统带Gui界面+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于MATLAB 的霍夫曼变换答题卡识别源码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab+bp神经网络的神经网络汉字识别系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页