Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of displaying Lunar Calendar time by ASP.NET

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "the method of displaying lunar calendar time by ASP.NET". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Take the class of lunar calendar time

The code is as follows:

Public class CountryDate

{

Public string ChineseTimeNow = ""

Public string ForignTimeNow = ""

Private static ChineseLunisolarCalendar calendar = new ChineseLunisolarCalendar ()

Private static string ChineseNumber = "01234 56789"

Public const string CelestialStem = "Methyl Ethylene Propylene pentane Gen Xin Rengui"

Public const string TerrestrialBranch = "Zi Chou Yin Mao Chen has not been declared in the afternoon."

Public static readonly string [] ChineseDayName = new string [] {

"the first year of junior high school", "the second year of junior high school", "the third year of junior high school", "the fourth year of junior high school", "the fifth year of junior high school", "the sixth year of junior high school", "the seventh day of junior high school", "eighth grade", "ninth grade", "tenth year of junior high school"

"11", "12", "13", "14", "15", "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", "eleven", "twelve"}

/ / /

/ / get the complete lunar calendar date corresponding to a Gregorian calendar date

/ / /

/ / A Gregorian calendar date

/ / Lunar calendar date

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

}

/ / /

/ / get the Gregorian calendar date of the Gregorian calendar

/ / /

/ / A Gregorian calendar date

/ / Lunar Calendar Ganzhi Chronicle

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

}

/ / /

/ / get the lunar year of a Gregorian calendar date

/ / /

/ / A Gregorian calendar date

/ / Lunar year

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

}

/ / /

/ / get the lunar month with a Gregorian calendar date

/ / /

/ / A Gregorian calendar date

/ Lunar month

Public string GetMonth (DateTime time)

{

Int month = calendar.GetMonth (time)

Int year = calendar.GetYear (time)

Int leap = 0

/ / the first month cannot be a leap month.

For (int I = 3; I 0) month--

Return (leap = = month + 1? "Leap": ") + ChineseMonthName [month-1]

}

/ / /

/ / get the lunar calendar day of a Gregorian calendar date

/ / /

/ / A Gregorian calendar date

/ / Lunar Calendar Day

Public string GetDay (DateTime time)

{

Return ChineseDayName [calendar.GetDayOfMonth (time)-1]

}

}

Required using

The copy code is as follows:

Using System

Using System.Collections.Generic

Using System.Web

Using System.Text

Using System.Globalization

Call:

The copy code is as follows:

CountryDate cd = new CountryDate ()

String ChineseTimeNow = cd.GetChineseDate (DateTime.Now); / / Lunar calendar date

String ForignTimeNow = DateTime.Now.GetDateTimeFormats ('D') [0] .ToString (); / / Gregorian calendar date

Here is the effect of a test:

Foreground code:

The copy code is as follows:

Background code:

The copy code is as follows:

Public partial class _ Default: System.Web.UI.Page

{

Protected void Page_Load (object sender, EventArgs e)

{

}

Protected void Button1_Click (object sender, EventArgs e)

{

CountryDate cd = new CountryDate ()

String ChineseTimeNow = cd.GetChineseDate (DateTime.Now); / / Lunar calendar date

String ForignTimeNow = DateTime.Now.GetDateTimeFormats ('D') [0] .ToString (); / / Gregorian calendar date

LblCountryDate.Text = ChineseTimeNow

LblForignDate.Text = ForignTimeNow

}

}

The running effect is shown in the following figure:

The main time is this CountryDate class, which can be called to take time.

This is the end of the content of "ASP.NET method for displaying Lunar Calendar time". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report