您好,登錄后才能下訂單哦!
小編給大家分享一下C#如何實現(xiàn)的陰歷陽歷互相轉(zhuǎn)化類,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
具體如下:
最近郁悶地發(fā)現(xiàn)網(wǎng)上現(xiàn)有的相當一部分萬年歷上干支紀年的算法都是錯誤的。因為干支紀年是針對陰歷而言的,而生肖屬相又跟地支對應,所以元旦和春節(jié)之間那段時間在干支紀年法中應該歸上一年,以陽歷2007年2月9日為例,當日的陰歷日期是二〇〇六年十二月廿二日,是丙戌年,即狗年,但是瀏覽一下目前的萬年歷,相當一部分都顯示成了丁亥年,豬年,比較郁悶~~
然后就寫了一個陰歷陽歷互相轉(zhuǎn)化的類。
相關代碼如下:
/// <summary> /// 中國日歷信息實體類 /// </summary> public sealed class ChineseCalendarInfo { private DateTime m_SolarDate; private int m_LunarYear, m_LunarMonth, m_LunarDay; private bool m_IsLeapMonth = false; private string m_LunarYearSexagenary = null, m_LunarYearAnimal = null; private string m_LunarYearText = null, m_LunarMonthText = null, m_LunarDayText = null; private string m_SolarWeekText = null, m_SolarConstellation = null, m_SolarBirthStone = null; 日歷屬性 /// <summary> /// 根據(jù)指定陽歷日期計算星座&誕生石 /// </summary> /// <param name="date">指定陽歷日期</param> /// <param name="constellation">星座</param> /// <param name="birthstone">誕生石</param> public static void CalcConstellation(DateTime date, out string constellation, out string birthstone) { int i = Convert.ToInt32(date.ToString("MMdd")); int j; if (i >= 321 && i <= 419) j = 0; else if (i >= 420 && i <= 520) j = 1; else if (i >= 521 && i <= 621) j = 2; else if (i >= 622 && i <= 722) j = 3; else if (i >= 723 && i <= 822) j = 4; else if (i >= 823 && i <= 922) j = 5; else if (i >= 923 && i <= 1023) j = 6; else if (i >= 1024 && i <= 1121) j = 7; else if (i >= 1122 && i <= 1221) j = 8; else if (i >= 1222 || i <= 119) j = 9; else if (i >= 120 && i <= 218) j = 10; else if (i >= 219 && i <= 320) j = 11; else { constellation = "未知星座"; birthstone = "未知誕生石"; return; } constellation = Constellations[j]; birthstone = BirthStones[j]; 星座劃分 } 陰歷轉(zhuǎn)陽歷 從陰歷創(chuàng)建日歷 private static ChineseLunisolarCalendar calendar = new ChineseLunisolarCalendar(); public const string ChineseNumber = "〇一二三四五六七八九"; public const string CelestialStem = "甲乙丙丁戊己庚辛壬癸"; public const string TerrestrialBranch = "子丑寅卯辰巳午未申酉戌亥"; public const string Animals = "鼠?;⑼谬埳唏R羊猴雞狗豬"; public static readonly string[] ChineseWeekName = new string[] { "星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; public static readonly string[] ChineseDayName = new string[] { "初一","初二","初三","初四","初五","初六","初七","初八","初九","初十", "十一","十二","十三","十四","十五","十六","十七","十八","十九","二十", "廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"}; public static readonly string[] ChineseMonthName = new string[] { "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" }; public static readonly string[] Constellations = new string[] { "白羊座", "金牛座", "雙子座", "巨蟹座", "獅子座", "處女座", "天秤座", "天蝎座", "射手座", "摩羯座", "水瓶座", "雙魚座" }; public static readonly string[] BirthStones = new string[] { "鉆石", "藍寶石", "瑪瑙", "珍珠", "紅寶石", "紅條紋瑪瑙", "藍寶石", "貓眼石", "黃寶石", "土耳其玉", "紫水晶", "月長石,血石" }; }
C#是一個簡單、通用、面向?qū)ο蟮木幊陶Z言,它由微軟Microsoft開發(fā),繼承了C和C++強大功能,并且去掉了一些它們的復雜特性,C#綜合了VB簡單的可視化操作和C++的高運行效率,以其強大的操作能力、優(yōu)雅的語法風格、創(chuàng)新的語言特性和便捷的面向組件編程從而成為.NET開發(fā)的首選語言,但它不適用于編寫時間急迫或性能非常高的代碼,因為C#缺乏性能極高的應用程序所需要的關鍵功能。
以上是“C#如何實現(xiàn)的陰歷陽歷互相轉(zhuǎn)化類”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業(yè)資訊頻道!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。