DateTime.IsLeapYear(Int32) 메서드

정의

지정된 연도가 윤년인지를 나타내는 표시를 반환합니다.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

매개 변수

year
Int32

4자리 연도입니다.A 4-digit year.

반환

true가 윤년이면 year이고, 그렇지 않으면 false입니다.true if year is a leap year; otherwise, false.

예외

year가 1보다 작거나 9999보다 큽니다.year is less than 1 or greater than 9999.

예제

다음 예제에서는 IsLeapYear 메서드를 사용 하 여 1994과 2014 사이의 연도를 윤년으로 확인 합니다.The following example uses the IsLeapYear method to determine which years between 1994 and 2014 are leap years. 또한이 예제에서는 AddYears 메서드를 사용 하 여 윤년에 연도를 더할 때의 결과를 보여 줍니다.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.

설명

year은 4 자리 밑수 10 숫자로 지정 됩니다. 예를 들면 1996입니다.year is specified as a 4-digit base 10 number; for example, 1996.

year은 항상 양력에서 연도로 해석 됩니다.year is always interpreted as a year in the Gregorian calendar. 특정 연도가 다른 달력에서 윤년 인지 여부를 확인 하려면 해당 달력 개체의 IsLeapYear 메서드를 호출 합니다.To determine whether a particular year was a leap year in some other calendar, call that calendar object's IsLeapYear method.

적용 대상