DateTime.IsLeapYear(Int32) Méthode

Définition

Retourne une indication confirmant si l'année spécifiée est une année bissextile.Returns an indication whether the specified year is a leap year.

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

Paramètres

year
Int32

Année sur 4 chiffres.A 4-digit year.

Retours

true si year est une année bissextile ; sinon, false.true if year is a leap year; otherwise, false.

Exceptions

year est inférieur à 1 ou supérieur à 9 999.year is less than 1 or greater than 9999.

Exemples

L’exemple suivant utilise la méthode IsLeapYear pour déterminer quelles années comprises entre 1994 et 2014 sont des années bissextiles.The following example uses the IsLeapYear method to determine which years between 1994 and 2014 are leap years. L’exemple illustre également le résultat lorsque la méthode AddYears est utilisée pour ajouter une année à une journée bissextile.The example also illustrates the result when the AddYears method is used to add a year to a leap day.

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.
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.

Remarques

year est spécifié sous la forme d’un nombre à quatre chiffres de base 10 ; par exemple, 1996.year is specified as a 4-digit base 10 number; for example, 1996.

year est toujours interprété comme une année dans le calendrier grégorien.year is always interpreted as a year in the Gregorian calendar. Pour déterminer si une année particulière était une année bissextile dans un autre calendrier, appelez la méthode IsLeapYear de cet objet de calendrier.To determine whether a particular year was a leap year in some other calendar, call that calendar object's IsLeapYear method.

S’applique à