﻿# 找到民國(TaiwanCalendar)與農曆(TaiwanLunisolarCalendar)的日曆類別

System.Globalization 這個命名空間很有趣，竟然有 TaiwanCalendar 與 TaiwanLunisolarCalendar 類別！

[TaiwanCalendar](http://msdn2.microsoft.com/zh-tw/library/system.globalization.taiwancalendar\(VS.80\).aspx) 是指台灣使用的曆法，也就是「民國年」的計算法。

> \[code:c#\]  
> DateTime now = new DateTime(2007, 12, 4);  
> TaiwanCalendar tc = new TaiwanCalendar();  
>   
> int year = tc.GetYear(now);  
> Console.WriteLine(year.ToString());  
> // Output : 96  
>   
> int month = tc.GetMonth(now);  
> Console.WriteLine(month.ToString());  
> // Output : 12  
>   
> int dayOfMonth = tc.GetDayOfMonth(now);  
> Console.WriteLine(dayOfMonth.ToString());  
> // Output : 4  
>   
> int daysInMonth = tc.GetDaysInMonth(year, month);  
> Console.WriteLine(daysInMonth.ToString());  
> // Output: 30  
> \[/code\]

[TaiwanLunisolarCalendar](http://msdn2.microsoft.com/zh-tw/library/system.globalization.taiwanlunisolarcalendar\(VS.80\).aspx) 是指台灣使用的陰陽曆（農曆）。和 TaiwanCalendar 相同，但可以使用西元年份計算，而日期和月份則使用陰陽曆計算，真的很省事！

> \[code:c#\]  
> TaiwanLunisolarCalendar tlc = new TaiwanLunisolarCalendar();
> 
> // 取得目前支援的農曆日曆到幾年幾月幾日( 2051-02-10 )  
> tlc.MaxSupportedDateTime.ToShortDateString();
> 
> // 取得今天的農曆年月日  
> txtContent.Text =  
>  tlc.GetYear(DateTime.Now).ToString() + "-" +  
>  tlc.GetMonth(DateTime.Now).ToString() + "-" +  
>  tlc.GetDayOfMonth(DateTime.Now).ToString();  
> \[/code\]
