Delphi XE3では、System.SysUtilsユニットのEraYearOffsets変数で和暦の始まりの年を取得できました。
uses
System.SysUtils;
var
I: Integer;
begin
for I := 1 to MaxEraCount do
begin
if EraNames[I].IsEmpty then
Continue;
Writeln(Format('%s元年は西暦%d年', [EraNames[I], EraYearOffsets[I]]));
end;
end.
実行結果
平成元年は西暦1989年
昭和元年は西暦1926年
大正元年は西暦1912年
明治元年は西暦1868年
Delphi XE5ではEraYearOffsets変数が廃止されています。
Delphi XE5で和暦の始まりの年を取得するにはSystem.SysUtilsユニットのTFormatSettingsを使用します。
uses
System.SysUtils;
var
FormatSettings: TFormatSettings;
EraInfo: TFormatSettings.TEraInfo;
begin
FormatSettings := TFormatSettings.Create;
for EraInfo in FormatSettings.EraInfo do
begin
Writeln(Format('%s元年は西暦%d年', [EraInfo.EraName, EraInfo.EraOffset]));
end;
end.
実行結果
平成元年は西暦1989年
昭和元年は西暦1926年
大正元年は西暦1912年
明治元年は西暦1868年