Home  |  Delphi .net Home  |  System.Globalization.Calendar  |  IsLeapYear Method
  
IsLeapYear  
Method  
Is specified Year a leap Year according to the current Calendar?
Calendar Class
System.Globalization NameSpace
CF1.  Function IsLeapYear ( Year : Integer ) : Boolean;
CF2.  Function IsLeapYear ( Year : Integer; Era : Integer ) : Boolean;
CF : Methods with this mark are Compact Framework Compatible
Description
Returns true if Year is a leap year according to the current Calendar culture.
 
Optionally, you may specify the Era for the year.
References
CultureInfo
Microsoft MSDN Links
System.Globalization
System.Globalization.Calendar
 Author links

 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Globalization;

var
  gbCulture : System.Globalization.CultureInfo;
  gbCal     : System.Globalization.Calendar;

  i         : Integer;

begin
  // Set up a Great Britain English culture & calendar
  gbCulture := System.Globalization.CultureInfo.Create('en-GB');
  gbCal     := gbCulture.Calendar;

  // Create a DateTime object : use the gbCalendar to control the
  // conversion of year, month and day parameter values into the
  // number of ticks since 1st January 0001 AD (the internal value)

  for i := 2000 to 2004 do
    if gbCal.IsLeapYear(i)
    then Console.WriteLine('{0} is a leap year', i.ToString)
    else Console.WriteLine('{0} is not a leap year', i.ToString);

  Console.ReadLine;
end.
   2000 is a leap year
   2001 is not a leap year
   2002 is not a leap year
   2003 is not a leap year
   2004 is a leap year
 
 
document.write('
'); document.write('
'); document.write('
');
Delphi Programming Neil Moffatt All rights reserved.  |  Contact the author