Lunar category in. Net framework2.0 (1)

Source: Internet
Author: User
I. Introduction
Chinese New Year ( As well as Japan, South Korea and other countries ) The first holiday of the people. How do you know the new year? Query the calendar or listen to others?ProgramOf course there is a programmer's approach, that is, writing a program.
Although ( Commonly known " Gregorian Calendar ") It has become a universal standard in the world and has many advantages. However, in East Asia " Lunar Calendar ", Spring Festival, Lantern Festival, Dragon Boat Festival, mid-autumn festival, Chongyang, these festivals are lunar calendar, most people's father and mother's birthday is also the lunar calendar.
As early 1.0 When the framework came out, I thought Microsoft should not " He is thin here " , In . Net The Framework provides Hebrew calendars, but does not provide more widely used " Lunar Calendar " .
In . NET 2.0 Microsoft finally made this small improvement.
. NET 2.0 In System. Globalization Added a new namespace Eastasianlunisolarcalendar Class to inherit its Chineselunisolarcalendar, japaneselunisolarcalendar, koreanlunisolarcalendar, taiwanlunisolarcalendar And so on. Lunisolarcalendar As the name implies " Yin and Yang " I understand that although the lunar calendar we use is based on the revolution of the moon " Leyue " To adjust the year and the Earth's revolution, strictly speaking, it is combined with the composition of the Moon's revolution and the Earth's revolution, so it belongs " Yin and Yang " . But here I still use it as a habit " Lunar Calendar " .

2. There is still no citizen treatment for the new Lunar Calendar category
To test the new calendar class, I wrote a fewCode:(Other code that calls this method is omitted.)

Private   String Getdatestring (datetime DT)
{
Cultureinfo Ci =   New Cultureinfo ( " Zh-CN " );
CI. datetimeformat. Calendar =   New Chineselunisolarcalendar ();
Return DT. tostring ( " D " , CI );
}

Error message:"Not a valid calendar for the given culture"

Continue testing to explain the problem

Private   String Getdatestring (datetime DT)
{
Cultureinfo Ci =   New Cultureinfo ( " Zh-TW " );
CI. datetimeformat. Calendar =   New Taiwancalendar ();
Return DT. tostring ( " D " , CI );
}

It can run normally. The result is95YearXMonthXDay(YEAR OF THE REPUBLIC OF CHINA)Comment out the middle statement. The result is2006YearXMonthXDay(That is, use the Gregorian Calendar), Modify the statement in the middle:CI. datetimeformat. Calendar =New Taiwanlunisolarcalendar(). Check the relevant information.DatetimeformatOfCalendarAttribute can only beCultureinfoOfOptionalcalendarsThe scope of the attribute.

write a code test optionalcalendars content, for ZH-CN language, the only calendar available for date format is localized gregoriancalendar ( that is, the Gregorian calendar ). For ZH-tw , calendar available for date formats is American English and localized gregoriancalendar and taiwancalendar ( that is, the year of the Gregorian calendar minus 1911) , do not include the lunar calendar.

That is to say. Net2.0Although the lunar calendar class is provided, the support for it is not the same as that for the Hebrew calendar with a leap month. When I checked the information, I found an article in the blog Hall.Http://blog.joycode.com/percyboy/archive/2004/09/17.aspxA year and a half ago, the author found that the lunar category does not support date formatting and thought this isBug. Of course not enough.BugBut Microsoft does not pay much attention to it.(Is it Microsoft? I don't think so. In commercial society, we will pay more attention to Microsoft. Compared with Israel, we place too much emphasis on traditional culture.).

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.