CS:
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 "};
Protected void page_load (Object sender, eventargs E)
{
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];
}
Front-end:
<Table Style = "">
<Tr valign = "bottom">
<TD valign = "bottom"> <% = forigntimenow %> <br/> </TD>
</Tr>
<Tr valign = "bottom">
<TD valign = "bottom"> <% = chinesetimenow %> </TD>
</Tr>
</Table>