ASP. NET display Lunar Calendar timeCodeYou can use it directly. datetime. Now shows the lunar calendar. Now, many people do not know the lunar calendar time even if they do not read the calendar.
This code is also found on the Internet and has not been changed.
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 ();
}