Einzelnen Beitrag anzeigen

Bjoerk

Registriert seit: 28. Feb 2011
Ort: Mannheim
1.384 Beiträge
 
Delphi 10.4 Sydney
 
#4

AW: Maske für FormatMaskText

  Alt 14. Feb 2015, 11:52
FormatMaskText ist ja mega kompliziert? Man kann sich ja zum Beispiel eine eigene function erstellen (uses DateUtils):
Delphi-Quellcode:
function ExtractDate(const Value: string; const Default: TDateTime): TDateTime;
var
  AYear, AMonth, ADay, AHour, AMinute, ASecond: word;
begin
  AYear := StrToIntDef(Copy(Value, 1, 4), 0);
  AMonth := StrToIntDef(Copy(Value, 6, 2), 0);
  ADay := StrToIntDef(Copy(Value, 9, 2), 0);
  AHour := StrToIntDef(Copy(Value, 12, 2), 0);
  AMinute := StrToIntDef(Copy(Value, 15, 2), 0);
  ASecond := StrToIntDef(Copy(Value, 18, 2), 0);
  if IsValidDateTime(AYear, AMonth, ADay, AHour, AMinute, ASecond, 0) then
    Result := EncodeDateTime(AYear, AMonth, ADay, AHour, AMinute, ASecond, 0)
  else
    Result := Default;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(DateTimeToStr(ExtractDate('2015-02-12_14-39-52', 0)));
end;
  Mit Zitat antworten Zitat