摘要:農曆
原始文件位置:http://www.dotblogs.com.tw/seanyhkao/archive/2009/12/21/12572.aspx
因為有時需要用到,故寫在自己部落格裡,以方便查詢。


01
DateTime date = DateTime.Today;02
TaiwanLunisolarCalendar LunisolarCalendar = new TaiwanLunisolarCalendar();03
string CelestialStem = "甲乙丙丁戊己庚辛壬癸";04
string TerrestrialBranch = "子丑寅卯辰巳午未申酉戌亥";05
int SexagenaryYear = LunisolarCalendar.GetSexagenaryYear(date);06
int CelestialStemYear = LunisolarCalendar.GetCelestialStem(SexagenaryYear);07
int TerrestrialBranchYear = LunisolarCalendar.GetTerrestrialBranch(SexagenaryYear);08
int LunisolarMonth = LunisolarCalendar.GetMonth(date);09
int LunisolarLeapMonth = LunisolarCalendar.GetLeapMonth(LunisolarCalendar.GetYear(date));10


if (LunisolarLeapMonth > 0 && LunisolarMonth >= LunisolarLeapMonth) ...{ LunisolarMonth -= 1; }11
int LunisolarDayOfMonth = LunisolarCalendar.GetDayOfMonth(date);12
int CelestialStemMonth = ((CelestialStemYear % 5) * 2 + LunisolarMonth - 1) % 10;13
int TerrestrialBranchMonth = (LunisolarMonth + 1) % 12;14
int cal_Year = date.Year;15
if (date.Month < 3) cal_Year--;16
int cal_Month = date.Month;17
if (date.Month < 3) cal_Month += 12;18
int A = (4 * (cal_Year / 100));19
int B = ((cal_Year / 100) / 4);20
int C = (5 * (cal_Year % 100));21
int D = ((cal_Year % 100) / 4);22
int E = (3 * (cal_Month + 1) / 5);23
int CelestialStemDay = (A + B + C + D + E + date.Day - 4) % 10;24
int TerrestrialBranchDay =(A + A + B + C + D + E + date.Day + 6 + (date.Month % 2 == 1 ? 0 : 6)) % 12;25
Response.Write(String.Format("...{0}年{1}月{2}日",SexagenaryYear,LunisolarMonth,LunisolarDayOfMonth));26


Response.Write(String.Format("...{0}{1}年{2}{3}月{4}{5}日",CelestialStem[CelestialStemYear - 1],TerrestrialBranch[(CelestialStemYear + 7) % 12],CelestialStem[CelestialStemMonth], TerrestrialBranch[TerrestrialBranchMonth],CelestialStem[CelestialStemDay], TerrestrialBranch[TerrestrialBranchDay]));