網站首頁 編程語言 正文
一、層次結構
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();//;五
原文鏈接:https://www.cnblogs.com/springsnow/p/9428640.html
相關推薦
- 2023-01-15 Python?networkx中獲取圖的鄰接矩陣方式_python
- 2022-05-28 教你C#將CSV轉為Excel的實現方法_C#教程
- 2021-12-15 Android?studio導出APP測試包和構建正式簽名包_Android
- 2022-08-14 協同開發巧用gitignore中間件避免網絡請求攜帶登錄信息_Golang
- 2024-01-29 在DOS或Windows環境中,使用工具Debug
- 2023-08-16 使用el-row和el-col實現快速布局
- 2022-08-13 圖像處理之matlab的取整函數round、ceil、floor和fix
- 2022-10-12 使用Docker搭建Vsftpd?的?FTP?服務的詳細過程_docker
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支