自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C#轉(zhuǎn)換農(nóng)歷的簡單方法

開發(fā) 后端
本文介紹C#轉(zhuǎn)換農(nóng)歷,改裝了一下如DateTime時間形式,實現(xiàn)了公歷農(nóng)歷轉(zhuǎn)換的功能,但是只能算到1900~2100年之間的。

C#轉(zhuǎn)換農(nóng)歷

原來還準(zhǔn)備自己寫算法,并研究農(nóng)歷規(guī)則。發(fā)現(xiàn)那太難和麻煩了,光是農(nóng)歷的推算那就我等專門研究歷法的人一下搞懂的。后來發(fā)現(xiàn).NET類庫也提供一些基礎(chǔ)的農(nóng)歷類System.Globalization.ChineseLunisolarCalendar。改裝了一下如DateTime時間形式,實現(xiàn)了公歷農(nóng)歷轉(zhuǎn)換的功能,但是只能算到1900~2100年之間的?;緣蛉粘J褂昧恕#轉(zhuǎn)換農(nóng)歷代碼如下:

  1. usingSystem;  
  2. usingSystem.Collections.Generic;  
  3. usingSystem.Text;  
  4.  
  5. namespaceSystem  
  6. ...{  
  7. /**////<summary> 
  8. ///中國常用農(nóng)歷日期時間類  
  9. ///zj53hao@qq.comhttp://hi.csdn.net/zj53hao  
  10. ///</summary> 
  11. classChinaDateTime  
  12. ...{  
  13. privateintyear,month,dayOfMonth;  
  14. privateboolisLeap;  
  15. publicDateTimetime;  
  16.  
  17. /**////<summary> 
  18. ///獲取當(dāng)前日期的農(nóng)歷年  
  19. ///</summary> 
  20. publicintYear  
  21. ...{  
  22. get...{returnyear;}  
  23. }  
  24.  
  25. /**////<summary> 
  26. ///獲取當(dāng)前日期的農(nóng)歷月份  
  27. ///</summary> 
  28. publicintMonth  
  29. ...{  
  30. get...{returnmonth;}  
  31. }  
  32.  
  33. /**////<summary> 
  34. ///獲取當(dāng)前日期的農(nóng)歷月中天數(shù)  
  35. ///</summary> 
  36. publicintDayOfMonth  
  37. ...{  
  38. get...{returndayOfMonth;}  
  39. }  
  40.  
  41. /**////<summary> 
  42. ///獲取當(dāng)前日期是否為閏月中的日期  
  43. ///</summary> 
  44. publicboolIsLeap  
  45. ...{  
  46. get...{returnisLeap;}  
  47. }  
  48.  
  49. System.Globalization.ChineseLunisolarCalendarcc;  
  50. /**////<summary> 
  51. ///返回指定公歷日期的陰歷時間  
  52. ///</summary> 
  53. ///<paramnameparamname="time"></param> 
  54. publicChinaDateTime(DateTimetime)  
  55. ...{  
  56. cc=newSystem.Globalization.ChineseLunisolarCalendar();  
  57.  
  58. if(time>cc.MaxSupportedDateTime||time<cc.MinSupportedDateTime)  
  59. thrownewException("參數(shù)日期時間不在支持的范圍內(nèi),支持范圍:
    "+cc.MinSupportedDateTime.ToShortDateString()+"到
    "+cc.MaxSupportedDateTime.ToShortDateString());  
  60. year=cc.GetYear(time);  
  61. month=cc.GetMonth(time);  
  62. dayOfMonth=cc.GetDayOfMonth(time);  
  63. isLeap=cc.IsLeapMonth(year,month);  
  64. if(isLeap)month-=1;  
  65. this.time=time;  
  66.  

以上介紹C#轉(zhuǎn)換農(nóng)歷

【編輯推薦】

  1. 定義C#接口學(xué)習(xí)經(jīng)驗
  2. C# ListBox學(xué)習(xí)筆記
  3. 操作C# Dataset介紹
  4. C# ODBC訪問MySQL數(shù)據(jù)庫
  5. 淺析C#和Java不同點
責(zé)任編輯:佚名 來源: IT168
相關(guān)推薦

2009-08-21 17:55:14

C#獲取攝像頭

2009-09-08 10:37:57

C#遍歷CheckBo

2009-08-19 13:06:37

C#操作注冊表

2009-08-28 09:55:15

C#時間間隔

2009-07-30 17:10:51

C#時間間隔

2009-08-24 14:14:56

C#導(dǎo)入Excel表

2009-08-20 16:25:59

C# 匿名方法

2009-08-14 17:27:56

C#方法參數(shù)

2009-07-30 15:57:30

C#時間

2010-08-06 13:23:58

NFS配置

2010-06-08 17:46:31

OpenSUSE安裝

2010-07-20 14:07:31

更改TELNET端口

2010-11-23 16:21:07

MySQL大表備份

2010-03-15 14:10:34

ubuntu系統(tǒng)

2010-09-30 14:01:38

2009-08-12 16:37:22

C#變量類型轉(zhuǎn)換

2011-05-18 13:37:26

LINQ

2011-04-06 09:09:17

MySQL數(shù)據(jù)庫備份

2010-03-03 13:56:43

Linux ubant

2009-02-05 14:48:51

跳出循環(huán)多層循環(huán)編程
點贊
收藏

51CTO技術(shù)棧公眾號