一、层次结构
Object<—–Calendar<—–EastAsianLunisolarCalendar<—–ChineseLunisolarCalendar农历)
二、用法
1、支持的最大,最小日期
System.Globalization.ChineseLunisolarCalendar cc =new System.Globalization.ChineseLunisolarCalendar); s1=cc.MinSupportedDateTime.ToString"");//02/19/1901 00:00:00 s2=cc.MaxSupportedDateTime.ToString"");//01/28/2101 23:59:59
2、单位农历天数
System.Globalization.ChineseLunisolarCalendar cc =new System.Globalization.ChineseLunisolarCalendar); s1=cc.GetMonthsInYearDateTime.Now.Year).ToString);//12,一年中有几个月,13表示当年有闰月。 s2=cc.GetDaysInYearDateTime.Now.Year).ToString);//354,一年中有多少天 s3=cc.GetDaysInMonthDateTime.Now.Year,DateTime.Now.Month).ToString);//29 ,当月中有多少天
3、天干、地支
System.Globalization.ChineseLunisolarCalendar cc =new System.Globalization.ChineseLunisolarCalendar); s1=cc.GetSexagenaryYearDateTime.Now ).ToString);//36,天干 s2=cc.GetTerrestrialBranch36).ToString);//12,地支
4、农历年、月、日
System.Globalization.ChineseLunisolarCalendar cc =new System.Globalization.ChineseLunisolarCalendar); s1=cc.GetYearDateTime.Now).ToString);//;2019 s2=cc.GetMonthDateTime.Now).ToString);//;5,注意:其返回值为1-13的数,如果该年四月有闰月,4月返回4,闰4月则返回5 s3=cc.GetDayOfMonthDateTime.Now).ToString);//;23
5、闰年与闰月
System.Globalization.ChineseLunisolarCalendar cc =new System.Globalization.ChineseLunisolarCalendar); s1=cc.IsLeapYearDateTime.Now.Year).ToString);//;False s2=cc.GetLeapMonthDateTime.Now.Year).ToString);//;0,注意:表示所闰月份。如果返回5,表示闰4月。
6、显示农历大写月份
string[] monthName = {"正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "东", "腊" }; System.Globalization.ChineseLunisolarCalendar cc = new System.Globalization.ChineseLunisolarCalendar); int currentMonth = cc.GetMonthDateTime.Today); int leapMonth = cc.GetLeapMonthDateTime.Today.Year); string realMonth; if currentMonth < leapMonth) realMonth = monthName[currentMonth]; else if currentMonth == leapMonth) realMonth = "闰" + monthName[currentMonth - 1]; else realMonth = monthName[currentMonth - 1]; s1 = realMonth.ToString);//;五