Asp. NET display method of Lunar time _ practical skills

Source: Internet
Author: User

This article illustrates how ASP.net displays the lunar time. Share to everyone for your reference. The implementation methods are as follows:

The CS section code is as follows:

Copy Code code as follows:
public string chinesetimenow = "";
public string forigntimenow = "";
private static Chineselunisolarcalendar calendar = new Chineselunisolarcalendar ();
private static string Chinesenumber = "0 123456789";
Public Const string Celestialstem = "A B-butyl Xing";
Public Const string Terrestrialbranch = "Kaniko chen has not Shin Hai";
public static readonly string[] Chinesedayname = new string[] {
"The Junior", "the Junior", "the Junior", "Hansi", "Duanwu", "Arrest", "When初七because", "Day", "Yanji", "decade",
"11", "12", "13", "14", "XV", "16", "17", "18", "19", "20",
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30"};
public static readonly string[] Chinesemonthname = new string[] {"Positive", "two", "three", "four", "five", "six", "seven", "eight", "Nine", "Ten", "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>
Gets the full lunar date for a Gregorian date
</summary>
<param name= "Time" > a Gregorian calendar date </param>
<returns> Lunar Date </returns>
public string getchinesedate (DateTime)
{
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>
Get a Gregorian calendar date of the lunar Ganzhi Annals
</summary>
<param name= "Time" > a Gregorian calendar date </param>
<returns> Lunar Ganzhi Annals </returns>
public string Getstembranch (DateTime)
{
int sexagenaryyear = Calendar. Getsexagenaryyear (time);
String stembranch = celestialstem.substring (sexagenaryyear% 10-1, 1) + terrestrialbranch.substring (sexagenaryYear% 12 -1, 1);
return stembranch;
}

<summary>
Gets the lunar year of a Gregorian date
</summary>
<param name= "Time" > a Gregorian calendar date </param>
<returns> Lunar Year </returns>
public string getyear (DateTime)
{
StringBuilder sb = new StringBuilder ();
int year = Calendar. GetYear (time);
int D;
Todo
{
d = year% 10;
Sb. Insert (0, chinesenumber[d]);
Year = YEAR/10;
while (year > 0);
Return SB. ToString ();
}

<summary>
Gets the lunar month of a Gregorian date
</summary>
<param name= "Time" > a Gregorian calendar date </param>
<returns> Lunar month </returns>
public string getmonth (DateTime)
{
int month = Calendar. GetMonth (time);
int year = Calendar. GetYear (time);
int leap = 0;

The lunar month cannot leap month
for (int i = 3; I <= month; i++)
{
if (Calendar. Isleapmonth (year, i))
{
leap = i;
Break There is up to one leap month in a year
}

}
if (Leap > 0) month--;
return (Leap = = month + 1?) "Leap": "" "+ chinesemonthname[month-1];
}

<summary>
Get the lunar day of a Gregorian date
</summary>
<param name= "Time" > a Gregorian calendar date </param>
<returns> Lunar Day </returns>
public string getday (DateTime)
{
Return Chinesedayname[calendar. GetDayOfMonth (Time)-1];
}

The front section code is as follows:

Copy Code code as follows:
<table style= "" >
<tr valign= "Bottom" >
<TD valign= "Bottom" > <%=forigntimenow%><br/></td>>
</tr>
<tr valign= "Bottom" >
<TD valign= "Bottom" > <%=chinesetimenow%></td>
</tr>
</table>

  Hope this article will help you with your asp.net programming.

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.