ASP. NET displays the lunar calendar time code, which can be directly used

Source: Internet
Author: User

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 ();
}

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.