DateTime.IsLeapYear(Int32) メソッド
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定された年が閏年かどうかを示す値を返します。
public:
static bool IsLeapYear(int year);
public static bool IsLeapYear(int year);
static member IsLeapYear : int -> bool
Public Shared Function IsLeapYear (year As Integer) As Boolean
- year
- Int32
4 桁の年。
true
が閏年である場合は year
。それ以外の場合は false
。
year
が 1 未満であるか、または 9999 を超えています。
次の例では、 メソッドを IsLeapYear 使用して、1994 年から 2014 年までの年が閏年かどうかを判断します。 この例では、 メソッドを使用して閏日に年を追加する場合 AddYears の結果も示しています。
using System;
public class IsLeapYear
{
public static void Main()
{
for (int year = 1994; year <= 2014; year++)
{
if (DateTime.IsLeapYear(year))
{
Console.WriteLine("{0} is a leap year.", year);
DateTime leapDay = new DateTime(year, 2, 29);
DateTime nextYear = leapDay.AddYears(1);
Console.WriteLine(" One year from {0} is {1}.",
leapDay.ToString("d"),
nextYear.ToString("d"));
}
}
}
}
// The example produces the following output:
// 1996 is a leap year.
// One year from 2/29/1996 is 2/28/1997.
// 2000 is a leap year.
// One year from 2/29/2000 is 2/28/2001.
// 2004 is a leap year.
// One year from 2/29/2004 is 2/28/2005.
// 2008 is a leap year.
// One year from 2/29/2008 is 2/28/2009.
// 2012 is a leap year.
// One year from 2/29/2012 is 2/28/2013.
open System
[ 1994..2014 ]
|> List.filter DateTime.IsLeapYear
|> List.iter (fun year ->
printfn $"{year} is a leap year."
let leapDay = DateTime(year, 2, 29)
let nextYear = leapDay.AddYears 1
printfn $" One year from {leapDay:d} is {nextYear:d}.")
// The example produces the following output:
// 1996 is a leap year.
// One year from 2/29/1996 is 2/28/1997.
// 2000 is a leap year.
// One year from 2/29/2000 is 2/28/2001.
// 2004 is a leap year.
// One year from 2/29/2004 is 2/28/2005.
// 2008 is a leap year.
// One year from 2/29/2008 is 2/28/2009.
// 2012 is a leap year.
// One year from 2/29/2012 is 2/28/2013.
Module IsLeapYear
Public Sub Main()
For year As Integer = 1994 to 2014
If DateTime.IsLeapYear(year) Then
Console.WriteLine("{0} is a leap year.", year)
Dim leapDay As New Date(year, 2, 29)
Dim nextYear As Date = leapDay.AddYears(1)
Console.WriteLine(" One year from {0} is {1}.", _
leapDay.ToString("d"), _
nextYear.ToString("d"))
End If
Next
End Sub
End Module
' The example displays the following output:
' 1996 is a leap year.
' One year from 2/29/1996 is 2/28/1997.
' 2000 is a leap year.
' One year from 2/29/2000 is 2/28/2001.
' 2004 is a leap year.
' One year from 2/29/2004 is 2/28/2005.
' 2008 is a leap year.
' One year from 2/29/2008 is 2/28/2009.
' 2012 is a leap year.
' One year from 2/29/2012 is 2/28/2013.
year
は 4 桁の底 10 番号として指定されます。たとえば、1996 年です。
year
は常にグレゴリオ暦の年として解釈されます。 特定の年が他のカレンダーの閏年かどうかを判断するには、そのカレンダー オブジェクトの IsLeapYear
メソッドを呼び出します。
製品 | バージョン |
---|---|
.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, 10 |
.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.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。