C#如何实现中文日历Calendar

发布时间:2022-05-10 13:43:26 作者:zzz
来源:亿速云 阅读:126

这篇文章主要讲解了“C#如何实现中文日历Calendar”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“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:59

2、单位农历天数

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();//;23

5、闰年与闰月

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这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

推荐阅读:
  1. Calendar实现blog日历的方法
  2. 基于Vue2-Calendar改进的日历组件(含中文使用说明)

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

calendar

上一篇:C#怎么实现石头剪刀布游戏

下一篇:C#如何使用随机数编写班级点名器

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》