Home  |  Delphi .net Home  |  System.Globalization.Calendar  |  IsLeapMonth Method
  
IsLeapMonth  
Method  
Is specified Year/Month a leap Month according to the current Calendar?
Calendar Class
System.Globalization NameSpace
CF1.  Function IsLeapMonth ( Year : Integer; Month : Integer ) : Boolean;
CF2.  Function IsLeapMonth ( Year : Integer; Month : Integer; Era : Integer ) : Boolean;
CF : Methods with this mark are Compact Framework Compatible
Description
Returns true if Year/Month is a leap month 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.IsLeapMonth(i, 2)
    then Console.WriteLine('February {0} is a leap month', i.ToString)
    else Console.WriteLine('February {0} is not a leap month', i.ToString);

  Console.ReadLine;
end.
   At the time of writing, this method fails to operate correctly :
   ----------------------------------------------------------------
  
   February 2000 is not a leap month
   February 2001 is not a leap month
   February 2002 is not a leap month
   February 2003 is not a leap month
   February 2004 is not a leap month
 
 
document.write('
'); document.write('
'); document.write('
');
Delphi Programming Neil Moffatt All rights reserved.  |  Contact the author