C#(99):中文日历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();//;五
复制代码

 

posted on   springsnow  阅读(1303)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!

导航

点击右上角即可分享
微信分享提示

目录导航