C # write your own calendar

Source: Internet
Author: User

Not to mention nonsense, go directly to the Code: [csharp] // TianGan private static string [] TianGan = {"A", "B", "C", "ding ", "E", "Ji", "Geng", "Xin", "Qu", "Xi"}; // private static string [] DiZhi = {"sub ", "ugly", "Yin", "Mao", "Chen", "Si", "Wu", "wei", "shen", "you", "shen ", "Hai"}; // 12 zodiac private static string [] ShengXiao = {"rat", "Ox", "Tiger", "rabbit", "dragon ", "snake", "horse", "goat", "monkey", "chicken", "dog", "Swine "}; // private static string [] DayName = {"*", "", "4th", "5th", "6th ", "Seventh Day", "Eighth Day", "Ninth Day", "tenth day", "eleventh day", "Twelve", "Thirteen", "Fourteen "," 15th "," 16th "," 17th "," 18th "," 19th "," 3 ", "Forty four", "Fifty five", "Sixty six", "Fifty seven", "Fifty eight", "Fifty nine", "Thirty "}; // private static string [] MonthName = {"*", "Zheng", "two", "three", "four", "five", "Six ", "7", "8", "9", "10", "11", "La "}; // calendar month count day private static int [] MonthAdd = {120,151,181,212,243,273,304,334, 267701,694,239,}; // calendar month data private static int [] LunarData = {2635,333387, 1701,1748, 133423, 1175,396438, 3402,3749, 331177,1453, 694,20 Listen, listen 197,3221, 3402,400 202,2901, clerk, 463853,1738, clerk, 1242,2651, 199255,1323, clerk, 1706,398762, 2741,1206, clerk, 1386,2413, clerk, clerk,, 1386,464219, 605,2349, 334123,2709, 2890,267946, 2773,592565, 1210,2651, 395863,1323, 2707,265877 }; /// <summary> /// obtain the calendar month of the corresponding date // </summary> /// <param name = "dtDay"> calendar date </param> ////// <returns> </returns> public string GetLunarCalendar (DateTime dtDay) {string sYear = dtDay. year. toString (); string sMonth = dtDay. month. toString (); string sDay = dtDay. day. toString (); int year; int month; int day; t Ry {year = int. parse (sYear); month = int. parse (sMonth); day = int. parse (sDay);} catch {year = DateTime. now. year; month = DateTime. now. month; day = DateTime. now. day;} int nTheDate; int nIsEnd; int k, m, n, nBit, I; string calendar = string. empty; // The number of days calculated to the initial date of January 1, 1921: February 8, 1921 (January 8, 365) nTheDate = (year-1921) * + (year) /4 + day + MonthAdd [month-1]-38; if (year % 4 = 0) & (mont H> 2) nTheDate + = 1; // computing day stem, local branch, month, day nIsEnd = 0; m = 0; k = 0; n = 0; while (nIsEnd! = 1) {if (LunarData [m] <4095) k = 11; else k = 12; n = k; while (n> = 0) {// obtain the nth binary value of LunarData [m] nBit = LunarData [m]; for (I = 1; I <n + 1; I ++) nBit = nBit/2; nBit = nBit % 2; if (nTheDate <= (29 + nBit) {nIsEnd = 1; break;} nTheDate = nTheDate-29-nBit; n = n-1;} if (nIsEnd = 1) break; m = m + 1;} year = 1921 + m; month = k-n + 1; day = nTheDate; # The format Date of region is displayed as January 1, lunar March 24 if (k = 12) {if (month = LunarData [m]/65536 + 1) month = 1-month; else if (month> LunarData [m]/65536 + 1) month = month-1;} // Zodiac // calendar = ShengXiao [(year-4) % 60% 12]. toString () + "year"; //// TianGan // calendar + = TianGan [(year-4) % 60% 10]. toString (); ///// /// calendar + = DiZhi [(year-4) % 60% 12]. toString () + ""; // lunar month // if (month <1) // calendar + = "calendar" + MonthName [-1 * month]. toString () + "month"; else calendar + = MonthName [month]. toString () + "month"; // lunar calendar day // calendar + = DayName [day]. toString () + "day"; // return calendar; // # endregion}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.