Export (0) Print
Expand All

JulianCalendar.IsLeapYear Method (Int32, Int32)

Determines whether the specified year in the specified era is a leap year.

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
Public Overrides Function IsLeapYear ( _
	year As Integer, _
	era As Integer _
) As Boolean

Parameters

year
Type: System.Int32

An integer that represents the year.

era
Type: System.Int32

An integer that represents the era.

Return Value

Type: System.Boolean
true if the specified year is a leap year; otherwise, false.

ExceptionCondition
ArgumentOutOfRangeException

year is outside the range supported by the calendar.

-or-

era is outside the range supported by the calendar.

Unlike the Gregorian calendar, the Julian calendar defines a leap year as a year that is evenly divisible by four with no exceptions. Therefore, the calendar is inaccurate by one day every 128 years. For example, the year 1999 was not a leap year, but the year 2000 was. A common year has 365 days and a leap year has 366 days.

The following example calls IsLeapYear for five years in each of the eras.

Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Public Class SamplesJulianCalendar   

   Public Shared Sub Main()

      ' Creates and initializes a JulianCalendar. 
      Dim myCal As New JulianCalendar()

      ' 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
         Console.Write(ControlChars.Tab + "{0}", myCal.IsLeapYear(y, JulianCalendar.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
            Console.Write(ControlChars.Tab + "{0}", myCal.IsLeapYear(y, myCal.Eras(i)))
         Next y
         Console.WriteLine()
      Next i

   End Sub 'Main 

End Class 'SamplesJulianCalendar


'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

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft