Einzelnen Beitrag anzeigen

Benutzerbild von peschai
peschai

Registriert seit: 15. Feb 2004
Ort: Göppingen
270 Beiträge
 
Delphi XE5 Professional
 
#4

AW: Formatierung der Datum und Zeit je nach Windows-Spracheinstellungen???

  Alt 1. Feb 2011, 21:16
Hallo

Vorschlag:

Delphi-Quellcode:
// Beispiel:
// s3 := '2008-09-23T14:15:22.984';
// dt6 := fctString2DateTime('YYYY MM DD HH NN SS ZZZ',s3);

function fctString2DateTime(const sFormat,sDateTimeString:String):TDateTime;
var
  i0 : integer;
  w1Year,w2Month,w3Day,w4Hour,w5Min,w6Sec,w7MSec:Word;
  i8 : Integer;
begin
  // local init
  Result := 0.0;
  i0 := 0;
  w1Year := 0;
  w2Month:= 0;
  w3Day := 0;
  w4Hour := 0;
  w5Min := 0;
  w6Sec := 0;
  w7MSec := 0;
  i8 := 0;
  // local main
  try
    if (Length(sFormat)=Length(sDateTimeString)) then
      begin
        for i8 := 1 to Length(sFormat) do
          begin
            i0 := Ord(sDateTimeString[i8])-48;
            if (i0>=0) and (i0<=9) then
              begin
                case sFormat[i8] of
                  'Y','y':w1Year := w1Year * 10 + i0;
                  'M','m':w2Month := w2Month * 10 + i0;
                  'D','d':w3Day := w3Day * 10 + i0;
                  'H','h':w4Hour := w4Hour * 10 + i0;
                  'N','n':w5Min := w5Min * 10 + i0;
                  'S','s':w6Sec := w6Sec * 10 + i0;
                  'Z','z':w7MSec := w7MSec * 10 + i0;
                end;
              end;
          end;
      end;
    Result := EncodeDateTime(w1Year,w2Month,w3Day,w4Hour,w5Min,w6Sec,w7MSec);
  except
    Result := 0.0;
  end;
end;
Peter Schaible
  Mit Zitat antworten Zitat