Home  |  Delphi .net Home  |  System.Globalization.Calendar  |  GetMonth Method
GetMonth  
Method  
Return the specified DateTime Month according to the current Calendar
Calendar Class
System.Globalization NameSpace
CF1.  Function GetMonth ( TheDateTime : DateTime; ) : Integer;
CF : Methods with this mark are Compact Framework Compatible
Description
Returns the Month value from TheDateTime value according to the current Calendar culture.
 
The GetMonth method converts the ticks value in TheDateTime (1 tick = 0.0000001 seconds since 1st Jan 0001 AD) into an internal representation of years, months, days according to the Calendar culture. It then returns the Month value according to this culture.
 
For example, in the Hebrew Calendar, there are between 353 and 355 days per common year, and 383 to 385 days in a leap year.
References
DateTime
CultureInfo
Microsoft MSDN Links
System.Globalization
System.Globalization.Calendar
 
 
Getting the Month for British and Arabic cultures
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('Era   = {0}', gbCal.GetEra(myDate).ToString);
  Console.WriteLine('Year  = {0}', gbCal.GetYear(myDate).ToString);
  Console.WriteLine('Month = {0}', gbCal.GetMonth(myDate).ToString);
  Console.WriteLine('Day   = {0}', gbCal.GetDayOfMonth(myDate).ToString);

  // Now use the Arabic calendar object to display this date
  Console.WriteLine;
  Console.WriteLine('Arabic calendar :');
  Console.WriteLine;
  Console.WriteLine('Era   = {0}', saCal.GetEra(myDate).ToString);
  Console.WriteLine('Year  = {0}', saCal.GetYear(myDate).ToString);
  Console.WriteLine('Month = {0}', saCal.GetMonth(myDate).ToString);
  Console.WriteLine('Day   = {0}', saCal.GetDayOfMonth(myDate).ToString);

  Console.ReadLine;
end.
Show full unit code
  British calendar :
  
  Era   = 1
  Year  = 2004
  Month = 12
  Day   = 8
  
  Arabic calendar :
  
  Era   = 1
  Year  = 1425
  Month = 10
  Day   = 26
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author