///
/// 将农历日期转换为阳历日期
///
/// 农历年份
/// 农历月份(1-12)
/// 农历日期(1-30)
/// 是否为闰月
///
public static DateTime ToDateTime(int lunarYear, int lunarMonth, int lunarDay, bool isLeapMonth = false)
{
DateTime solarDate;
try
{
int leapMonth = CLC.GetLeapMonth(lunarYear);
if (isLeapMonth) lunarMonth++;
else
{
if (leapMonth != 0 && leapMonth < lunarMonth)
{
lunarMonth++;
}
}
int daysInMonth = CLC.GetDaysInMonth(lunarYear, lunarMonth);
if (lunarDay > daysInMonth)
throw new ArgumentOutOfRangeException($"农历{lunarYear}年{lunarMonth}月中只有{daysInMonth}天,参数日期{lunarDay}无效");
solarDate = CLC.ToDateTime(lunarYear, lunarMonth, lunarDay, 0, 0, 0, 0);
}
catch
{
throw new ArgumentOutOfRangeException($"无效的农历日期:{lunarYear}-{lunarMonth}-{lunarDay}日。");
}
return solarDate;
}