这篇文章介绍了C#实现中文日历Calendar的方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
一、层次结构
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:592、单位农历天数
System.Globalization.ChineseLunisolarCalendar cc =new System.Globalization.ChineseLunisolarCalendar();
s1=cc.GetMonthsInYear(DateTime.Now.Year).ToString();//12,一年中有几个月,13表示当年有闰月。
s2=cc.GetDaysInYear(DateTime.Now.Year).ToString();//354,一年中有多少天
s3=cc.GetDaysInMonth(DateTime.Now.Year,DateTime.Now.Month).ToString();//29 ,当月中有多少天3、天干、地支
System.Globalization.ChineseLunisolarCalendar cc =new System.Globalization.ChineseLunisolarCalendar();
s1=cc.GetSexagenaryYear(DateTime.Now ).ToString();//36,天干
s2=cc.GetTerrestrialBranch(36).ToString();//12,地支4、农历年、月、日
System.Globalization.ChineseLunisolarCalendar cc =new System.Globalization.ChineseLunisolarCalendar();
s1=cc.GetYear(DateTime.Now).ToString();//;2019
s2=cc.GetMonth(DateTime.Now).ToString();//;5,注意:其返回值为1-13的数,如果该年四月有闰月,4月返回4,闰4月则返回5
s3=cc.GetDayOfMonth(DateTime.Now).ToString();//;235、闰年与闰月
System.Globalization.ChineseLunisolarCalendar cc =new System.Globalization.ChineseLunisolarCalendar();
s1=cc.IsLeapYear(DateTime.Now.Year).ToString();//;False
s2=cc.GetLeapMonth(DateTime.Now.Year).ToString();//;0,注意:表示所闰月份。如果返回5,表示闰4月。6、显示农历大写月份
string[] monthName = {"正",  "二", "三", "四", "五", "六", "七", "八", "九", "十", "东", "腊" };
System.Globalization.ChineseLunisolarCalendar cc = new System.Globalization.ChineseLunisolarCalendar();
int currentMonth = cc.GetMonth(DateTime.Today);
int leapMonth = cc.GetLeapMonth(DateTime.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();//;五到此这篇关于C#实现中文日历Calendar的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持得得之家。
				 沃梦达教程
				
			本文标题为:C#实现中文日历Calendar
				
        
 
            
        
             猜你喜欢
        
	     - WPF使用DrawingContext实现绘制刻度条 2023-07-04
 - Unity3D实现渐变颜色效果 2023-01-16
 - Unity Shader实现模糊效果 2023-04-27
 - Oracle中for循环的使用方法 2023-07-04
 - user32.dll 函数说明小结 2022-12-26
 - 在C# 8中如何使用默认接口方法详解 2023-03-29
 - C# 使用Aspose.Cells 导出Excel的步骤及问题记录 2023-05-16
 - c# 模拟线性回归的示例 2023-03-14
 - .NET CORE DI 依赖注入 2023-09-27
 - 如何使用C# 捕获进程输出 2023-03-10
 
						
						
						
						
						
				
				
				
				