Home  |  Delphi .net Home  |  System.Globalization.Calendar  |  ToFourDigitYear Method
ToFourDigitYear  
Method  
Converts a 2 digit year safely to a 4 digit year for the current Calendar
Calendar Class
System.Globalization NameSpace
CF1.  Function ToFourDigitYear ( Year : Integer; ) : Integer;
CF : Methods with this mark are Compact Framework Compatible
Description
The 2 digit Year value is checked against the TwoDigitYearMax property.
 
The following example demonstrates :
 
TwoDigitYearMax  = 2029
Year = 28  Result = 2028
Year = 29  Result = 2029
Year = 30  Result = 1930
References
CultureInfo
Microsoft MSDN Links
System.Globalization
System.Globalization.Calendar
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Globalization;

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

  i         : Integer;

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

  Console.WriteLine('TwoDigitYearMax = {0}',
                    gbCal.TwoDigitYearMax.ToString);

  Console.WriteLine;

  // Convert 2 digit years to a 4 digit years
  for i := 28 to 31 do
    Console.WriteLine('{0} becomes {1}',
                      i.ToString, gbCal.ToFourDigitYear(i).ToString);

  Console.ReadLine;
end.
Show full unit code
  TwoDigitYearMax = 2029
  
  28 becomes 2028
  29 becomes 2029
  30 becomes 1930
  31 becomes 1931
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author