C#
C# 양력 음력 변환
miraclewing
2020. 1. 16. 13:58
1. 양력 -> 음력 변환
public string ToLunarDate(string _year, string _month, string _day)
{
KoreanLunisolarCalendar klc = new KoreanLunisolarCalendar();
int year = Convert.ToInt32(_year);
int month = Convert.ToInt32(_month);
int day = Convert.ToInt32(_day);
if (klc.GetMonthsInYear(year) > 12)
{
int leapMonth = klc.GetLeapMonth(year);
if (month >= leapMonth)
{
month--;
}
}
return new DateTime(year, month, day).ToString("yyyy-MM-dd");
}
2. 음력 -> 양력 변환
public string ToSolarDate(string _year, string _month, string _day, bool isLeapMonth = false)
{
KoreanLunisolarCalendar klc = new KoreanLunisolarCalendar();
int year = Convert.ToInt32(_year);
int month = Convert.ToInt32(_month);
int day = Convert.ToInt32(_day);
if (klc.GetMonthsInYear(year) > 12)
{
int leapMonth = klc.GetLeapMonth(year);
if (month > leapMonth - 1)
{
month++;
}
else if (month == leapMonth - 1 && isLeapMonth)
{
month++;
}
}
return klc.ToDateTime(year, month, day, 0, 0, 0, 0).ToString("yyyy-MM-dd");
}