C#實(shí)現(xiàn)中文日歷Calendar
一、層次結(jié)構(gòu)
Object<-----Calendar<-----EastAsianLunisolarCalendar<-----ChineseLunisolarCalendar(農(nóng)歷)
二、用法
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、單位農(nóng)歷天數(shù)
System.Globalization.ChineseLunisolarCalendar cc =new System.Globalization.ChineseLunisolarCalendar(); s1=cc.GetMonthsInYear(DateTime.Now.Year).ToString();//12,一年中有幾個月,13表示當(dāng)年有閏月。 s2=cc.GetDaysInYear(DateTime.Now.Year).ToString();//354,一年中有多少天 s3=cc.GetDaysInMonth(DateTime.Now.Year,DateTime.Now.Month).ToString();//29 ,當(dāng)月中有多少天
3、天干、地支
System.Globalization.ChineseLunisolarCalendar cc =new System.Globalization.ChineseLunisolarCalendar(); s1=cc.GetSexagenaryYear(DateTime.Now ).ToString();//36,天干 s2=cc.GetTerrestrialBranch(36).ToString();//12,地支
4、農(nóng)歷年、月、日
System.Globalization.ChineseLunisolarCalendar cc =new System.Globalization.ChineseLunisolarCalendar(); s1=cc.GetYear(DateTime.Now).ToString();//;2019 s2=cc.GetMonth(DateTime.Now).ToString();//;5,注意:其返回值為1-13的數(shù),如果該年四月有閏月,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、顯示農(nóng)歷大寫月份
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();//;五到此這篇關(guān)于C#實(shí)現(xiàn)中文日歷Calendar的文章就介紹到這了。希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C# .Net實(shí)現(xiàn)灰度圖和HeatMap熱力圖winform(進(jìn)階)
本文主要介紹了C# .NET實(shí)現(xiàn)簡易灰度圖和酷炫HeatMap熱力圖winform,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-12-12
基于C#的UDP協(xié)議的同步通信實(shí)現(xiàn)代碼
本篇文章主要介紹了基于C#的UDP協(xié)議的同步實(shí)現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02
C# 實(shí)現(xiàn)截圖軟件功能實(shí)例代碼
這篇文章主要介紹了C# 實(shí)現(xiàn)截圖軟件功能實(shí)例代碼,需要的朋友可以參考下2017-06-06
C#使用SendMessage實(shí)現(xiàn)進(jìn)程間通信的方法
這篇文章主要介紹了C#使用SendMessage實(shí)現(xiàn)進(jìn)程間通信的方法,涉及C#中SendMessage方法的使用技巧,非常具有實(shí)用價值,需要的朋友可以參考下2015-04-04
C#使用TCP協(xié)議實(shí)現(xiàn)數(shù)據(jù)發(fā)送和接受的方法
這篇文章主要介紹了c#使用TCP協(xié)議實(shí)現(xiàn)數(shù)據(jù)發(fā)送和接受,使用TCP協(xié)議實(shí)現(xiàn)數(shù)據(jù)的發(fā)送和接受包括客戶端和服務(wù)端兩個部分,本文通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-04-04

