DateTime.IsLeapYear Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Returns an indication whether the specified year is a leap year.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- year
- Type: System.Int32
A 4-digit year.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | year is less than 1 or greater than 9999. |
The following example uses the IsLeapYear method to determine which years between 1994 and 2014 are leap years. The example also illustrates the result when the AddYears method is used to add a year to a leap day.
Module Example Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) For year As Integer = 1994 To 2014 If DateTime.IsLeapYear(year) Then outputBlock.Text += String.Format("{0} is a leap year.", year) & vbCrLf Dim leapDay As New Date(year, 2, 29) Dim nextYear As Date = leapDay.AddYears(1) outputBlock.Text += String.Format(" One year from {0} is {1}.", _ leapDay.ToString("d"), _ nextYear.ToString("d")) & vbCrLf 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.
Show: