JapaneseCalendar.IsLeapYear(Int32, Int32) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
确定指定纪元中的指定年份是否为闰年。
public:
override bool IsLeapYear(int year, int era);
public override bool IsLeapYear (int year, int era);
override this.IsLeapYear : int * int -> bool
Public Overrides Function IsLeapYear (year As Integer, era As Integer) As Boolean
参数
- year
- Int32
一个整数,用于表示年份。
- era
- Int32
一个整数,用于表示纪元。
返回
如果指定的年份是闰年,则为 true
;否则为 false
。
例外
示例
以下示例在每个纪元中调用 IsLeapYear 五年。 示例输出中的当前纪元是 Reiwa 纪元。
using namespace System;
using namespace System::Globalization;
int main()
{
// Creates and initializes a JapaneseCalendar.
JapaneseCalendar^ myCal = gcnew JapaneseCalendar;
// Displays the header.
Console::Write( "YEAR\t" );
for ( int y = 1; y <= 5; y++ )
Console::Write( "\t {0}", y );
Console::WriteLine();
// Checks five years in the current era.
Console::Write( "CurrentEra:" );
for ( int y = 1; y <= 5; y++ )
Console::Write( "\t {0}", myCal->IsLeapYear( y, JapaneseCalendar::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 = 1; y <= 5; y++ )
Console::Write( "\t {0}", myCal->IsLeapYear( y, myCal->Eras[ i ] ) );
Console::WriteLine();
}
}
/*
This code produces the following output.
YEAR 1 2 3 4 5
CurrentEra: False True False False False
Era 5: False True False False False
Era 4: False False False True False
Era 3: False False True False False
Era 2: True False False False True
Era 1: True False False False True
*/
using System;
using System.Globalization;
public class SamplesJapaneseCalendar
{
public static void Main()
{
// Creates and initializes a JapaneseCalendar.
JapaneseCalendar myCal = new JapaneseCalendar();
// Displays the header.
Console.Write( "YEAR\t" );
for ( int y = 1; y <= 5; y++ )
Console.Write( "\t{0}", y );
Console.WriteLine();
// Checks five years in the current era.
Console.Write( "CurrentEra:" );
for ( int y = 1; y <= 5; y++ )
Console.Write( "\t{0}", myCal.IsLeapYear( y, JapaneseCalendar.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 = 1; y <= 5; y++ )
Console.Write( "\t{0}", myCal.IsLeapYear( y, myCal.Eras[i] ) );
Console.WriteLine();
}
}
}
/*
This code produces the following output.
YEAR 1 2 3 4 5
CurrentEra: False True False False False
Era 5: False True False False False
Era 4: False False False True False
Era 3: False False True False False
Era 2: True False False False True
Era 1: True False False False True
*/
Imports System.Globalization
Public Class SamplesJapaneseCalendar
Public Shared Sub Main()
' Creates and initializes a JapaneseCalendar.
Dim myCal As New JapaneseCalendar()
' Displays the header.
Console.Write("YEAR" + ControlChars.Tab)
Dim y As Integer
For y = 1 To 5
Console.Write(ControlChars.Tab + "{0}", y)
Next
Console.WriteLine()
' Checks five years in the current era.
Console.Write("CurrentEra:")
For y = 1 To 5
Console.Write(ControlChars.Tab + "{0}", myCal.IsLeapYear(y, JapaneseCalendar.CurrentEra))
Next
Console.WriteLine()
' Checks five years in each of the eras.
For i As Integer = 0 To myCal.Eras.Length - 1
Console.Write("Era {0}:" + ControlChars.Tab, myCal.Eras(i))
For y = 1 To 5
Console.Write(ControlChars.Tab + "{0}", myCal.IsLeapYear(y, myCal.Eras(i)))
Next
Console.WriteLine()
Next
End Sub
End Class
'This code produces the following output.
'
' YEAR 1 2 3 4 5
' CurrentEra: False True False False False
' Era 5: False True False False False
' Era 4: False False False True False
' Era 3: False False True False False
' Era 2: True False False False True
' Era 1: True False False False True
注解
日本历中的闰年对应于公历中的同一闰年。 公历中的闰年定义为公历的公历年,除可被 100 整除外,公历年可被 4 均匀地整除。 然而,被400整除的公历年是闰年。 普通年份有 365 天,闰年有 366 天。