GregorianCalendar.IsLeapDay メソッド (Int32, Int32, Int32, Int32)
指定した時代 (年号) の指定した日付が閏日かどうかを確認します。
Overrides Overloads Public Function IsLeapDay( _
ByVal year As Integer, _ ByVal month As Integer, _ ByVal day As Integer, _ ByVal era As Integer _) As Boolean
[C#]
public override bool IsLeapDay(intyear,intmonth,intday,intera);
[C++]
public: bool IsLeapDay(intyear,intmonth,intday,intera);
[JScript]
public override function IsLeapDay(
year : int,month : int,day : int,era : int) : Boolean;
パラメータ
- year
年を表す整数。 - month
月を表す 1 ~ 12 の整数。 - day
日を表す 1 ~ 31 の整数。 - era
時代 (年号) を表す整数。
戻り値
指定した日が閏日である場合は true 。それ以外の場合は false 。
例外
例外の種類 | 条件 |
---|---|
ArgumentOutOfRangeException | year が暦でサポートされている範囲外の値です。
または month が暦でサポートされている範囲外の値です。 または day が暦でサポートされている範囲外の値です。 |
ArgumentException | era が暦でサポートされている範囲外の値です。 |
解説
グレゴリオ暦の閏年は、100 で割り切れる年を除く、4 で割り切れる年として定義されていますが、400 で割り切れる年は閏年になります。たとえば、1900 年は閏年ではありませんでしたが、2000 年は閏年でした。平年の日数は 365 日で、閏年の日数は 366 日です。
閏日は、閏年にだけ訪れる日です。グレゴリオ暦では、2 月 29 日は唯一の閏日です。
使用例
[Visual Basic, C#, C++] 各時代 (年号) の 5 年ごとの 2 番目の月 (2 月) の最後の日の IsLeapDay を呼び出す例を次に示します。
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic
Public Class SamplesGregorianCalendar
Public Shared Sub Main()
' Creates and initializes a GregorianCalendar.
Dim myCal As New GregorianCalendar()
' Creates a holder for the last day of the second month (February).
Dim iLastDay As Integer
' Displays the header.
Console.Write("YEAR" + ControlChars.Tab)
Dim y As Integer
For y = 2001 To 2005
Console.Write(ControlChars.Tab + "{0}", y)
Next y
Console.WriteLine()
' Checks five years in the current era.
Console.Write("CurrentEra:")
For y = 2001 To 2005
iLastDay = myCal.GetDaysInMonth(y, 2, GregorianCalendar.CurrentEra)
Console.Write(ControlChars.Tab + "{0}", myCal.IsLeapDay(y, 2, iLastDay, GregorianCalendar.CurrentEra))
Next y
Console.WriteLine()
' Checks five years in each of the eras.
Dim i As Integer
For i = 0 To myCal.Eras.Length - 1
Console.Write("Era {0}:" + ControlChars.Tab, myCal.Eras(i))
For y = 2001 To 2005
iLastDay = myCal.GetDaysInMonth(y, 2, myCal.Eras(i))
Console.Write(ControlChars.Tab + "{0}", myCal.IsLeapDay(y, 2, iLastDay, myCal.Eras(i)))
Next y
Console.WriteLine()
Next i
End Sub 'Main
End Class 'SamplesGregorianCalendar
'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
[C#]
using System;
using System.Globalization;
public class SamplesGregorianCalendar {
public static void Main() {
// Creates and initializes a GregorianCalendar.
GregorianCalendar myCal = new GregorianCalendar();
// Creates a holder for the last day of the second month (February).
int iLastDay;
// 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++ ) {
iLastDay = myCal.GetDaysInMonth( y, 2, GregorianCalendar.CurrentEra );
Console.Write( "\t{0}", myCal.IsLeapDay( y, 2, iLastDay, GregorianCalendar.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++ ) {
iLastDay = myCal.GetDaysInMonth( y, 2, myCal.Eras[i] );
Console.Write( "\t{0}", myCal.IsLeapDay( y, 2, iLastDay, 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
*/
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;
int main()
{
// Creates and initializes a GregorianCalendar.
GregorianCalendar* myCal = new GregorianCalendar();
// Creates a holder for the last day of the second month (February).
int iLastDay;
// Displays the header.
Console::Write(S"YEAR\t");
for (int y = 2001; y <= 2005; y++)
Console::Write(S"\t {0}", __box(y));
Console::WriteLine();
// Checks five years in the current era.
Console::Write(S"CurrentEra:");
for (int y = 2001; y <= 2005; y++)
{
iLastDay = myCal -> GetDaysInMonth(y, 2, GregorianCalendar::CurrentEra);
Console::Write(S"\t {0}", __box(myCal -> IsLeapDay(y, 2, iLastDay, GregorianCalendar::CurrentEra)));
}
Console::WriteLine();
// Checks five years in each of the eras.
for (int i = 0; i < myCal -> Eras -> Length; i++)
{
Console::Write(S"Era {0}:\t", myCal -> Eras->Item[i]);
for (int y = 2001; y <= 2005; y++)
{
iLastDay = myCal -> GetDaysInMonth(y, 2, myCal -> Eras[i]);
Console::Write(S"\t {0}", __box(myCal -> IsLeapDay(y, 2, iLastDay, 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
*/
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
GregorianCalendar クラス | GregorianCalendar メンバ | System.Globalization 名前空間 | GregorianCalendar.IsLeapDay オーバーロードの一覧 | CurrentEra | ADEra | Eras | GetMonthsInYear | GetDaysInMonth | IsLeapYear | IsLeapMonth