Asp. NET how to display Chinese lunar time
The CS section code is as follows:
The code is as follows: public string chinesetimenow = "";
public string forigntimenow = "";
private static Chineselunisolarcalendar calendar = new Chineselunisolarcalendar ();
private static string Chinesenumber = "0 123456789";
Public Const string Celestialstem = "Methyl-n-Xing";
Public Const string Terrestrialbranch = "Obscure Chen has not Shin Hai";
public static readonly string[] Chinesedayname = new string[] {
"The Junior", "Second day", "Third Day", "four", "Duanwu", "Arrest", "When初七because", "Holidays", "Penggushan", "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 a Gregorian date corresponding to the full lunar date
</summary>
<param name= "Time" > a Gregorian date </param>
<returns> Lunar Dates </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>
Get a Gregorian calendar date for the lunar Ganzhi
</summary>
<param name= "Time" > a Gregorian date </param>
<returns> Lunar Ganzhi Annals </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>
Gets the lunar year of a Gregorian date
</summary>
<param name= "Time" > a Gregorian date </param>
<returns> Lunar Year </returns>
public string GetYear (DateTime time)
{
nbsp 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 ();
}
It Classic laugh: the programmer in the eyes of women: Some women are like windows, although very good, but security is too big. Some women are like Unix. She has a good condition, but not everyone can play. Some women are like C # long beautiful, but housework is not. Some women are like C + +, she will silently do a lot of things for you. Some women are like Java, and just a little bit of it will serve you everywhere. Some women are like Java script, although they are careful with her, but ultimately there is no result. Some women are like the assembly, although it is troublesome, but sometimes they have to ask for it.
<summary>
Gets the lunar month of a Gregorian date
</summary>
<param name= "Time" > a Gregorian date </param>
<returns> Lunar month </returns>
public string GetMonth (DateTime time)
{
int month = Calendar. GetMonth (time);
int year = Calendar. GetYear (time);
int leap = 0;
The lunar month cannot leap
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?) "Leap": "") + chinesemonthname[month-1];
}
<summary>
Get a Gregorian date on the lunar day
</summary>
<param name= "Time" > a Gregorian date </param>
<returns> Lunar Day </returns>
public string GetDay (DateTime time)
{
Return Chinesedayname[calendar. GetDayOfMonth (Time)-1];
}
The front section code is as follows:
The 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>
From:http://www.codes51.com/article/detail_93960.html
Asp. NET how to display Chinese lunar time