Home  |  Delphi .net Home  |  System.Globalization.Calendar  |  GetDaysInYear Method
GetDaysInYear  
Method  
Gets the number of Days in a Year according to the current Calendar
Calendar Class
System.Globalization NameSpace
CF1.  Function GetDaysInYear ( Year : Integer; ) : Integer ;
CF2.  Function GetDaysInYear ( Year:IntegerYear : Integer; Era : Integer; ) : Integer;
CF : Methods with this mark are Compact Framework Compatible
Description
Returns the number of Days in the given Year and, optionally, Era according to the current Calendar.
References
CultureInfo
Microsoft MSDN Links
System.Globalization
System.Globalization.Calendar
 
 
Getting the Days in a Year using British and Arabic calendars
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Globalization;

var
  myDate    : DateTime;

  gbCulture : System.Globalization.CultureInfo;
  saCulture : System.Globalization.CultureInfo;

  gbCal     : System.Globalization.Calendar;
  saCal     : System.Globalization.Calendar;

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

  // Set up a Saudi Arabia Arabic culture & calendar
  saCulture := System.Globalization.CultureInfo.Create('ar-SA');
  saCal     := saCulture.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)
  // Note : Gregorian Calendar is used by default anyway
  myDate := DateTime.Create(2004, 12, 8, gbCal);  // 8th December 2004

  // Now use the British calendar object to display this date
  Console.WriteLine('British calendar :');
  Console.WriteLine;
  Console.WriteLine('Days   in month = {0}',
                    gbCal.GetDaysInMonth(2004, 12).ToString);
  Console.WriteLine('Days   in  year = {0}',
                    gbCal.GetDaysInYear(2004).ToString);
  Console.WriteLine('Months in  year = {0}',
                    gbCal.GetMonthsInYear(2004).ToString);

  // Now use the Arabic calendar object to display this date
  Console.WriteLine;
  Console.WriteLine('Arabic calendar :');
  Console.WriteLine;
  Console.WriteLine('Days   in month = {0}',
                    saCal.GetDaysInMonth(2004, 12).ToString);
  Console.WriteLine('Days   in  year = {0}',
                    saCal.GetDaysInYear(2004).ToString);
  Console.WriteLine('Months in  year = {0}',
                    saCal.GetMonthsInYear(2004).ToString);

  Console.ReadLine;
end.
Show full unit code
  British calendar :
  
  Days   in month = 31
  Days   in  year = 366
  Months in  year = 12
  
  Arabic calendar :
  
  Days   in month = 30
  Days   in  year = 355
  Months in  year = 12
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author