C # (ASP. NET) a simple method for converting calendars to calendars

Source: Internet
Author: User

The Dot Net platform is very good at global support and has to be praised

Generally, converting a Gregorian calendar into a lunar calendar is a very annoying task. You need to sort out the comparison tables for the year and month.

On the. Net platform, with international support, all these things have been provided. What we need to do is to take advantage of them.

If you don't talk much about it, go directly to the Code:

 

/// <Summary> /// functions for converting the Gregorian calendar into the lunar calendar /// </summary> /// <remarks> author: deltaCat </remarks> // <example> URL: http://www.zu14.cn </example> /// <param name = "solarDateTime"> date of the Gregorian calendar </param> /// <returns> date of the lunar calendar </returns> static string SolarToChineseLunisolarDate (DateTime solarDateTime) {System. globalization. chineseLunisolarCalendar cal = new System. globalization. chineseLunisolarCalendar (); int year = cal. getYear (solarDateTim E); int month = cal. getMonth (solarDateTime); int day = cal. getDayOfMonth (solarDateTime); int leapMonth = cal. getLeapMonth (year); return string. format ("lunar month {0} {1} ({2}) {3} {4} month {5} {6 }", "A, B, C, E, E, G, Xin, Xi" [(year-4) % 10], "Zi ugly Yin, Mao Chen, Wu, Wu, Xi Wei, Hai" [(year-4) % 12], "Rat, ox, Tiger, Rabbit, dragon, Snake, horse, monkey, chicken, dog, and pig" [(year-4) % 12], month = leapMonth? "Week": "", "normal June 80 or 90 winter wax" [leapMonth> 0 & leapMonth <= month? Month-1: month], "day 10, day 3" [day/10], "day 1234, day 5, day 6, day 9" [day % 10]);}

 

The method is very simple:

String lunar calendar = SolarToChineseLunisolarDate (DateTime. Today );

[Read the full text]

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.