モバイル デバイスの FireMonkey で文字列を TDateTime に変換するときに問題が発生しました。
常にエラーが発生し、どうすればよいかわかりません。
私が何をしているかをお見せします:
function StringToDateTime(DateStr: String): TDateTime;
var
FS: TFormatSettings;
begin
result := now;
FS:= TFormatSettings.Create;
FS.DateSeparator := '-';
FS.DateSeparator := ':';
FS.ShortDateFormat := 'dd-mm-yyyy';
FS.ShortTimeFormat := 'hh:nn:ss';
try
Result := StrToDateTime(DateStr, FS); //the format of the string is :
// dd-mm-yyyy hh:nn:ss '31-03-2015 9:36:00'
except on E: Exception do
ShowMessage(e.ToString);
end;
end;
例外は次のとおりです。
「31-03-2015 9:36:00」は有効な日時ではありません。