GregorianCalendar.IsLeapMonth(Int32, Int32, Int32) 方法

定義

判斷指定紀元的指定年份中指定的月份是否為閏月。

public:
 override bool IsLeapMonth(int year, int month, int era);
public override bool IsLeapMonth (int year, int month, int era);
override this.IsLeapMonth : int * int * int -> bool
Public Overrides Function IsLeapMonth (year As Integer, month As Integer, era As Integer) As Boolean

參數

year
Int32

表示年份的整數。

month
Int32

從 1 到 12 的整數,表示月份。

era
Int32

表示紀元的整數。

傳回

這個方法永遠傳回 false,除非被衍生類別 (Derived Class) 所覆寫。

例外狀況

era 不在曆法支援的範圍內。

-或-

year 不在曆法支援的範圍內。

-或-

month 不在曆法支援的範圍內。

範例

下列程式代碼範例會針對目前紀元五年的所有月份呼叫 IsLeapMonth。

using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Creates and initializes a GregorianCalendar.
   GregorianCalendar^ myCal = gcnew GregorianCalendar;
   
   // Checks all the months in five years in the current era.
   int iMonthsInYear;
   for ( int y = 2001; y <= 2005; y++ )
   {
      Console::Write( " {0}:\t", y );
      iMonthsInYear = myCal->GetMonthsInYear( y, GregorianCalendar::CurrentEra );
      for ( int m = 1; m <= iMonthsInYear; m++ )
         Console::Write( "\t {0}", myCal->IsLeapMonth( y, m, GregorianCalendar::CurrentEra ) );
      Console::WriteLine();

   }
}

/*
This code produces the following output.

2001:           False   False   False   False   False   False   False   False   False   False   False   False
2002:           False   False   False   False   False   False   False   False   False   False   False   False
2003:           False   False   False   False   False   False   False   False   False   False   False   False
2004:           False   False   False   False   False   False   False   False   False   False   False   False
2005:           False   False   False   False   False   False   False   False   False   False   False   False

*/
using System;
using System.Globalization;

public class SamplesGregorianCalendar  {

   public static void Main()  {

      // Creates and initializes a GregorianCalendar.
      GregorianCalendar myCal = new GregorianCalendar();

      // Checks all the months in five years in the current era.
      int iMonthsInYear;
      for ( int y = 2001; y <= 2005; y++ )  {
         Console.Write( "{0}:\t", y );
         iMonthsInYear = myCal.GetMonthsInYear( y, GregorianCalendar.CurrentEra );
         for ( int m = 1; m <= iMonthsInYear; m++ )
            Console.Write( "\t{0}", myCal.IsLeapMonth( y, m, GregorianCalendar.CurrentEra ) );
         Console.WriteLine();
      }
   }
}

/*
This code produces the following output.

2001:           False   False   False   False   False   False   False   False   False   False   False   False
2002:           False   False   False   False   False   False   False   False   False   False   False   False
2003:           False   False   False   False   False   False   False   False   False   False   False   False
2004:           False   False   False   False   False   False   False   False   False   False   False   False
2005:           False   False   False   False   False   False   False   False   False   False   False   False

*/
Imports System.Globalization

Public Class SamplesGregorianCalendar   
   
   Public Shared Sub Main()

      ' Creates and initializes a GregorianCalendar.
      Dim myCal As New GregorianCalendar()

      ' Checks all the months in five years in the current era.
      Dim iMonthsInYear As Integer
      Dim y As Integer
      For y = 2001 To 2005
         Console.Write("{0}:" + ControlChars.Tab, y)
         iMonthsInYear = myCal.GetMonthsInYear(y, GregorianCalendar.CurrentEra)
         Dim m As Integer
         For m = 1 To iMonthsInYear
            Console.Write(ControlChars.Tab + "{0}", myCal.IsLeapMonth(y, m, GregorianCalendar.CurrentEra))
         Next m
         Console.WriteLine()
      Next y

   End Sub

End Class


'This code produces the following output.
'
'2001:           False   False   False   False   False   False   False   False   False   False   False   False
'2002:           False   False   False   False   False   False   False   False   False   False   False   False
'2003:           False   False   False   False   False   False   False   False   False   False   False   False
'2004:           False   False   False   False   False   False   False   False   False   False   False   False
'2005:           False   False   False   False   False   False   False   False   False   False   False   False

備註

公曆中的閏年會定義為一年,該年份會平均除四,但如果 100 會將其除開。 不過,400 可除的年份是閏年。 例如,1900 年不是閏年,而是 2000 年。 一般年份有 365 天,而閏年有 366 天。

閏月是只發生在閏年的整個月份。 公曆沒有任何閏月。

適用於

另請參閱