Date displayed with the lunar calendar and date displayed with the lunar calendar

Source: Internet
Author: User

Date displayed with the lunar calendar and date displayed with the lunar calendar

In the near future, the company needs to make a hotel reservation function with date controls, similar to what network hotel reservation, because you need to set the price for different periods of holidays, you need to write a time control. This section describes the lunar calendar display classes used in the write time control.

Because it was the first time I wrote something in the blog, I don't know what the final display format will look like. Sorry!

Public class CnCalendar
{
Static ChineseLunisolarCalendar cCalendar = new ChineseLunisolarCalendar ();
Public static string GetChineseDateTime (DateTime datetime)
{
String strDate = datetime. Month + "Month" + datetime. Day + "Day ";
Int lyear = cCalendar. GetYear (datetime );
Int lmonth = cCalendar. GetMonth (datetime );
Int lday = cCalendar. GetDayOfMonth (datetime );
// Obtain the leap month. If the value is 0, no leap month exists.
Int leapMonth = cCalendar. GetLeapMonth (lyear );
Bool isleap = false;
If (leapMonth> 0)
{
If (leapMonth = lmonth)
{
// Leap month
Isleap = true;
Lmonth --;
}
Else if (lmonth> leapMonth)
{
Lmonth --;
}
}
If (strDate = "January 1 ")
{
Return "<em class = 'calendarnljieri '> New Year's Day </em> ";
}
Else if (strDate = "February 14 ")
{
Return "<em class = 'calendarnljieri '> Valentine's Day </em> ";
}
Else if (strDate = "March 8 ")
{
Return "<em class = 'calendarnljieri '> Women's Day </em> ";
}
Else if (strDate = "March 12 ")
{
Return "<em class = 'calendarnljieri '> Arbor Day </em> ";
}
Else if (strDate = "April 1 ")
{
Return "<em class = 'calendarnljieri '> fools </em> ";
}
Else if (strDate = "May 1 ")
{
Return "<em class = 'calendarnljieri '> Labor Day </em> ";
}
Else if (strDate = "May 4 ")
{
Return "<em class = 'calendarnljieri '> Youth Day </em> ";
}
Else if (strDate = "June 1 ")
{
Return "<em class = 'calendarnljieri '> Children's Day </em> ";
}
Else if (strDate = "August 1 ")
{
Return "<em class = 'calendarnljieri '> army building festival </em> ";
}
Else if (strDate = "September 10 ")
{
Return "<em class = 'calendarnljieri '> Teacher's Day </em> ";
}
Else if (strDate = "October 1 ")
{
Return "<em class = 'calendarnljieri '> National Day </em> ";
}
Else
{
If (lday = 1)
{
Return "<em class = 'calendarnl '>" +
String. Concat (isleap? "Months": string. Empty, GetLunisolarMonth (lmonth), "month") + "</em> ";
}
Else
{
String strNongli = string. Concat (isleap? "Months": string. Empty, GetLunisolarMonth (lmonth), "month ",
GetLunisolarDay (lday ));
Switch (strNongli)
{
Case "Lunar January 1 ":
Return "<em class = 'calendarnljieri '> spring festival </em> ";
Case "Lunar January 15 ":
Return "<em class = 'calendarnljieri '> Lantern Festival </em> ";
Case "the fifth day of May ":
Return "<em class = 'calendarnljieri '> Dragon Boat Festival </em> ";
Case "seventh day of July ":
Return "<em class = 'calendarnljieri '> Tanabata </em> ";
Case "August 15 ":
Return "<em class = 'calendarnljieri '> Mid-Autumn Festival </em> ";
Case "the ninth day of September ":
Return "<em class = 'calendarnljieri '> Chongyang Festival </em> ";
Case "Lunar December 8 ":
Return "<em class = 'calendarnljieri '> labay </em> ";
Case "Lunar December 24 ":
Return "<em class = 'calendarnljieri '> house Sweeping Festival </em> ";
Default:
Return "<em class = 'calendarnl '>" + GetLunisolarDay (lday) + "</em> ";
}
}
}
}

# Region
/// <Summary>
/// Ten days
/// </Summary>
Private static string [] tiangan = {"A", "B", "C", "ding", "E", "Ji", "Geng", "Xin ", "yellow", "yellow "};

/// <Summary>
/// 12 local branches
/// </Summary>
Private static string [] dizhi = {"sub", "ugly", "Yin", "Mao", "Chen", "Si", "Wu", "wei ", "shen", "you", "shen", "Hai "};

/// <Summary>
/// Zodiac
/// </Summary>
Private static string [] shengxiao = {"rat", "Ox", "Tiger", "free", "dragon", "snake", "horse", "goat ", "monkey", "chicken", "dog", "Swine "};

/// <Summary>
/// Return to the calendar year
/// </Summary>
/// <Param name = "year"> calendar year </param>
/// <Returns> </returns>
Public static string GetLunisolarYear (int year)
{
If (year> 3)
{
Int tgIndex = (year-4) % 10;
Int dzIndex = (year-4) % 12;

Return string. Concat (tiangan [tgIndex], dizhi [dzIndex], "[", shengxiao [dzIndex], "]");

}

Throw new ArgumentOutOfRangeException ("invalid year! ");
}
# Endregion

# Region lunar month

/// <Summary>
/// Lunar month
/// </Summary>
Private static string [] months = {"zheng", "2", "3", "4", "5", "6", "7", "8 ", "9", "10", "11", "Lunar December "};


/// <Summary>
/// Return to the lunar month
/// </Summary>
/// <Param name = "month"> month </param>
/// <Returns> </returns>
Public static string GetLunisolarMonth (int month)
{
If (month <13 & month> 0)
{
Return months [month-1];
}

Throw new ArgumentOutOfRangeException ("invalid month! ");
}


# Endregion

# Region lunar day

/// <Summary>
///
/// </Summary>
Private static string [] days1 = {"", "10", "Hangzhou", "3 "};

/// <Summary>
/// Day
/// </Summary>
Private static string [] days = {"1", "2", "3", "4", "5", "6", "7", "8 ", "9", "10 "};


/// <Summary>
/// Return to the lunar calendar day
/// </Summary>
/// <Param name = "day"> </param>
/// <Returns> </returns>
Public static string GetLunisolarDay (int day)
{
If (day> 0 & day <32)
{
If (day! = 20 & day! = 30)
{
Return string. Concat (days1 [(day-1)/10], days [(day-1) % 10]);
}
Else
{
Return string. Concat (days [(day-1)/10], days1 [1]);
}
}

Throw new ArgumentOutOfRangeException ("invalid day! ");
}

# Endregion

/// <Summary>
/// Return to the Chinese zodiac
/// </Summary>
/// <Param name = "datetime"> calendar date </param>
/// <Returns> </returns>
Public static string GetShengXiao (DateTime datetime)
{
Return shengxiao [cCalendar. GetTerrestrialBranch (cCalendar. GetSexagenaryYear (datetime)-1];
}
}

 

 

Judging the festival, I don't know if you have any suggestions.


My computer shows no calendar for the date?

Install a calendar display software to show which calendar type is used!

How can I display the lunar date in the lower right corner of the desktop?

There are a lot of alarm and calendar software that can display the lunar calendar in the lower right corner. Some XP modified versions install such software by default, such as XP's tornado version, you should select repair in the Add/delete program to display it again. However, it is recommended to disable this function to save resource consumption. You can manually select to view the required information!

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.