This article illustrates how ASP.net displays the lunar time. Share to everyone for your reference. The implementation methods are 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];
}
Hope this article will help you with your asp.net programming.