ASP. NET: how to display the lunar calendar time, asp.net: how to display the lunar calendar

Source: Internet
Author: User

ASP. NET: how to display the lunar calendar time, asp.net: how to display the lunar calendar

This article describes how ASP. NET displays the lunar calendar time. Share it with you for your reference. The specific implementation method is as follows:

Part of the CS code is as follows:
Copy codeThe Code is as follows: public string ChineseTimeNow = "";
Public string ForignTimeNow = "";
Private static ChineseLunisolarCalendar calendar = new ChineseLunisolarCalendar ();
Private static string ChineseNumber = "1234 ";
Public const string CelestialStem = "A, B, C, E, Ji, Geng, Xin, Xi ";
Public const string TerrestrialBranch = "zi ";
Public static readonly string [] ChineseDayName = new string [] {
"First Day", "Second Day", "Third Day", "fourth day", "Fifth Day", "Sixth Day", "Seventh Day", "Eighth Day", "Ninth Day", "tenth day ",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20 ",
"Jun 1", "Jun 2", "Jun 3", "Jun 4", "Jun 5", "Jun 6", "Jun 7", "Jun 8 ", "9th", "30th "};
Public static readonly string [] ChineseMonthName = new string [] {"zheng", "two", "three", "four", "five", "Six ", "7", "8", "9", "10", "11", "12 "};

Override protected void Page_Load (object sender, EventArgs e)
{
Base. Page_Load (sender, e );
UserName = Session ["Admin"]. ToString ();
ChineseTimeNow = GetChineseDate (DateTime. Now );
ForignTimeNow = DateTime. Now. GetDateTimeFormats ('D') [0]. ToString ();
}

/// <Summary>
/// Obtain the complete lunar date corresponding to a calendar date
/// </Summary>
/// <Param name = "time"> one calendar date </param>
/// <Returns> lunar date </returns>
Public string GetChineseDate (DateTime time)
{
String strY = GetYear (time );
String strM = GetMonth (time );
String strD = GetDay (time );
String strSB = GetStemBranch (time );
String strDate = strY + "(" + strSB + ") Year" + strM + "month" + strD;
Return strDate;
}
/// <Summary>
/// Obtain the calendar year for a calendar date
/// </Summary>
/// <Param name = "time"> one calendar date </param>
/// <Returns> calendar year </returns>
Public string GetStemBranch (DateTime time)
{
Int sexagenaryYear = calendar. GetSexagenaryYear (time );
String stemBranch = CelestialStem. Substring (sexagenaryYear % 10-1, 1) + TerrestrialBranch. Substring (sexagenaryYear % 12-1, 1 );
Return stemBranch;
}

/// <Summary>
/// Obtain the year of the calendar year of a calendar date
/// </Summary>
/// <Param name = "time"> one calendar date </param>
/// <Returns> lunar year </returns>
Public string GetYear (DateTime time)
{
StringBuilder sb = new StringBuilder ();
Int year = calendar. GetYear (time );
Int d;
Do
{
D = year % 10;
Sb. Insert (0, ChineseNumber [d]);
Year = year/10;
} While (year> 0 );
Return sb. ToString ();
}

/// <Summary>
/// Obtain the calendar month of a calendar date
/// </Summary>
/// <Param name = "time"> one calendar date </param>
/// <Returns> lunar month </returns>
Public string GetMonth (DateTime time)
{
Int month = calendar. GetMonth (time );
Int year = calendar. GetYear (time );
Int leap = 0;

// It cannot be a leap month in lunar January
For (int I = 3; I <= month; I ++)
{
If (calendar. IsLeapMonth (year, I ))
{
Leap = I;
Break; // up to one leap month in a year
}

}
If (leap> 0) month --;
Return (leap = month + 1? "Region": "") + ChineseMonthName [month-1];
}

/// <Summary>
/// Obtain the calendar day of a calendar date
/// </Summary>
/// <Param name = "time"> one calendar date </param>
/// <Returns> lunar day </returns>
Public string GetDay (DateTime time)
{
Return ChineseDayName [calendar. GetDayOfMonth (time)-1];
}

The front-end code is as follows:
Copy codeThe Code is as follows: <table style = "">
<Tr valign = "bottom">
<Td valign = "bottom"> <% = ForignTimeNow %> <br/> </td>
</Tr>
<Tr valign = "bottom">
<Td valign = "bottom"> <% = ChineseTimeNow %> </td>
</Tr>
</Table>

I hope this article will help you design ASP. NET programs.

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.