英語で読む

次の方法で共有


JulianCalendar.IsLeapYear(Int32, Int32) メソッド

定義

指定した時代 (年号) の指定した年が閏年かどうかを確認します。

C#
public override bool IsLeapYear (int year, int era);

パラメーター

year
Int32

年を表す整数。

era
Int32

時代 (年号) を表す整数。

戻り値

指定した年が閏年である場合は true。それ以外の場合は false

例外

year が暦でサポートされている範囲外です。

- または -

era が暦でサポートされている範囲外です。

次の例では、各時代の 5 年間を呼び出 IsLeapYear します。

C#
using System;
using System.Globalization;

public class SamplesJulianCalendar  {

   public static void Main()  {

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

      // Displays the header.
      Console.Write( "YEAR\t" );
      for ( int y = 2001; y <= 2005; y++ )
         Console.Write( "\t{0}", y );
      Console.WriteLine();

      // Checks five years in the current era.
      Console.Write( "CurrentEra:" );
      for ( int y = 2001; y <= 2005; y++ )
         Console.Write( "\t{0}", myCal.IsLeapYear( y, JulianCalendar.CurrentEra ) );
      Console.WriteLine();

      // Checks five years in each of the eras.
      for ( int i = 0; i < myCal.Eras.Length; i++ )  {
         Console.Write( "Era {0}:\t", myCal.Eras[i] );
         for ( int y = 2001; y <= 2005; y++ )
            Console.Write( "\t{0}", myCal.IsLeapYear( y, myCal.Eras[i] ) );
         Console.WriteLine();
      }
   }
}

/*
This code produces the following output.

YEAR            2001    2002    2003    2004    2005
CurrentEra:     False   False   False   True    False
Era 1:          False   False   False   True    False

*/

注釈

グレゴリオ暦とは異なり、ユリウス暦は閏年を年として定義します。これは例外なく、4 つで均等に割り切れる年です。 そのため、カレンダーは 128 年ごとに 1 日ずつ不正確になります。 たとえば、1999 年は閏年ではなく、2000 年でした。 平年は 365 日で、閏年は 366 日です。

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

こちらもご覧ください