日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > C# >内容正文

C#

C# 将系统时间转换成农历时间

發(fā)布時(shí)間:2023/12/18 C# 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C# 将系统时间转换成农历时间 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

直接上代碼:

1 using System; 2 using System.Collections.Generic; 3 using System.Text; 4 5 namespace RSMISClient 6 { 7 using System.Globalization; 8 public static class ChineseDate 9 { 10 private static ChineseLunisolarCalendar cCalendar = new ChineseLunisolarCalendar(); 11 //cCalendar.MaxSupportedDateTime 返回支持的最大日期,即2101-1-28 12 //cCalendar.MinSupportedDateTime 返回支持的最小日期,即1901-2-19 13 14 #region 農(nóng)歷年 15 /// <summary> 16 /// 十天干 17 /// </summary> 18 private static string[] tiangan = { "", "", "", "", "", "", "", "", "", "" }; 19 20 /// <summary> 21 /// 十二地支 22 /// </summary> 23 private static string[] dizhi = { "", "", "", "", "", "", "", "", "", "", "", "" }; 24 25 /// <summary> 26 /// 十二生肖 27 /// </summary> 28 private static string[] shengxiao = { "", "", "", "", "", "", "", "", "", "", "", "" }; 29 30 /// <summary> 31 /// 返回農(nóng)歷天干地支年 32 /// </summary> 33 /// <param name="year">農(nóng)歷年</param> 34 /// <returns></returns> 35 public static string GetLunisolarYear(int year) 36 { 37 if (year > 3) 38 { 39 int tgIndex = (year - 4) % 10; 40 int dzIndex = (year - 4) % 12; 41 42 return string.Concat(tiangan[tgIndex], dizhi[dzIndex], "[", shengxiao[dzIndex], "]"); 43 } 44 45 throw new ArgumentOutOfRangeException("無(wú)效的年份!"); 46 } 47 #endregion 48 49 #region 農(nóng)歷月 50 /// <summary> 51 /// 農(nóng)歷月 52 /// </summary> 53 private static string[] months = { "", "", "", "", "", "", "", "", "", "", "十一(冬)", "十二(臘)" }; 54 55 /// <summary> 56 /// 返回農(nóng)歷月 57 /// </summary> 58 /// <param name="month">月份</param> 59 /// <returns></returns> 60 public static string GetLunisolarMonth(int month) 61 { 62 if (month < 13 && month > 0) 63 { 64 return months[month - 1]; 65 } 66 67 throw new ArgumentOutOfRangeException("無(wú)效的月份!"); 68 } 69 #endregion 70 71 #region 農(nóng)歷日 72 /// <summary> 73 /// 74 /// </summary> 75 private static string[] days1 = { "", "", "廿", "" }; 76 77 /// <summary> 78 /// 79 /// </summary> 80 private static string[] days = { "", "", "", "", "", "", "", "", "", "" }; 81 82 /// <summary> 83 /// 返回農(nóng)歷日 84 /// </summary> 85 /// <param name="day"></param> 86 /// <returns></returns> 87 public static string GetLunisolarDay(int day) 88 { 89 if (day > 0 && day < 32) 90 { 91 if (day != 20 && day != 30) 92 { 93 return string.Concat(days1[(day - 1) / 10], days[(day - 1) % 10]); 94 } 95 else 96 { 97 return string.Concat(days[(day - 1) / 10], days1[1]); 98 } 99 } 100 101 throw new ArgumentOutOfRangeException("無(wú)效的日!"); 102 } 103 #endregion 104 105 #region 方法 106 public static string GetChineseDateTime(DateTime datetime) 107 { 108 int lyear = cCalendar.GetYear(datetime); 109 int lmonth = cCalendar.GetMonth(datetime); 110 int lday = cCalendar.GetDayOfMonth(datetime); 111 112 //獲取閏月, 0 則表示沒(méi)有閏月 113 int leapMonth = cCalendar.GetLeapMonth(lyear); 114 bool isleap = false; 115 116 if (leapMonth > 0) 117 { 118 if (leapMonth == lmonth) 119 { 120 //閏月 121 isleap = true; 122 lmonth--; 123 } 124 else if (lmonth > leapMonth) 125 { 126 lmonth--; 127 } 128 } 129 130 return string.Concat(GetLunisolarYear(lyear), "", isleap ? "" : string.Empty, GetLunisolarMonth(lmonth), "月·", GetLunisolarDay(lday)); 131 } 132 #endregion 133 } 134 135 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/Jins/archive/2013/06/06/3122732.html

總結(jié)

以上是生活随笔為你收集整理的C# 将系统时间转换成农历时间的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。