Net2.0 provides the conversion function between the Gregorian calendar and the lunar calendar. The following is a few simple examples of its usage.
Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. Globalization;
/**
* Note: In addition to the general Year of the year,
* It is an abstract class and has various subclasses for different countries. ChineseLunisolarCalendar is a calendar class for China. It refers to the conversion between the Chinese calendar year and the Chinese traditional calendar year.
* This program can be used to calculate information about the lunar calendar, such as the dianchuang. It can calculate the range of the lunar calendar from 1-2-19 to 2101-1-28.
* Author: Zhou Gong
* Date: 2007-11-21
* Last maintenance Date:
* First address: http://blog.csdn.net/zhoufoxcn/archive/2007/11/21/1896258.aspx
*/
Namespace ChineseCalendar
{
Class Calendar
{
Private static ChineseLunisolarCalendar chineseDate = new ChineseLunisolarCalendar ();
Static void Main (string [] args)
{
// ChineseLunisolarCalendar chineseDate = new ChineseLunisolarCalendar ();
ShowYearInfo ();
ShowCurrentYearInfo ();
Console. ReadLine ();
}
/// <Summary>
/// Display the calendar year information
/// </Summary>
Public static void ShowYearInfo ()
{
For (int I = chineseDate. MinSupportedDateTime. Year; I <chineseDate. MaxSupportedDateTime. Year; I ++)
{
Console. writeLine ("Year: {0}, total number of months: {1}, total number of days: {2}, stem number: {3}", I, chineseDate. getMonthsInYear (I), chineseDate. getDaysInYear (I)
, ChineseDate. GetSexagenaryYear (new DateTime (I, 3, 1 )));
}
}
/// <Summary>
/// Display the current year information
/// </Summary>
Public static void ShowCurrentYearInfo ()
{
/* The GetLeapMonth (int year) method returns a number between 1 and 13,
* For example: 1. If there is a leap month in the lunar calendar month of this year, 3 is returned.
* If: 2, there is a leap month in the lunar calendar month of this year, 9 is returned.
* GetMonth (DateTime dateTime) returns the current month, ignoring whether it is a leap month.
* For example: 1. There is a leap month in the lunar calendar month of this year, 2 is returned on April 9, 3 is returned on April 9, and 3 is returned on April 9 ,.
* If: 2, there is a leap month in the lunar calendar month of this year, 8 is returned on April 9, and 9 is returned on April 9 ,.
*/
Int leapMonth = chineseDate. GetLeapMonth (DateTime. Now. Year); // obtain the month in which it is a leap month. If it is equal to 0, it indicates that this Year has no leap month.
Int lYear = chineseDate. GetYear (DateTime. Now );
Int lMonth = chineseDate. GetMonth (DateTime. Now );
Int lDay = chineseDate. GetDayOfMonth (DateTime. Now );
// If a leap month exists this year
If (leapMonth> 0)
{
// The number of leap months equals to the current month
If (lMonth = leapMonth)
{
Console. WriteLine ("calendar date of this year: {0}-Mmm {1}-{2. ", LYear, lMonth-1, lDay );
}
Else if (lMonth> leapMonth )//
{
Console. WriteLine ("calendar date of this year: {0}-{1}-{2. ", LYear, lMonth-1, lDay );
}
Else
{
Console. WriteLine ("calendar date of this year: {0}-{1}-{2. ", LYear, lMonth, lDay );
}
&