我希望以下代码能够工作:
program Project3;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
var
FS: TFormatSettings;
const
DF = 'yyyymmdd';
begin
try
WriteLn(FormatDateTime(DF, Now));
FS := TFormatSettings.Create;
FS.ShortDateFormat := DF;
WriteLn(StrToDate('20121219', FS));
ReadLn;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
为什么会抛出异常,说“20121219”不是有效日期?这不正是通过 TFormatSettings 应该做的吗?