![]() |
Datumsstring formatiert nach TDateTime
Ich würde gerne einen Datum-Zeit-String aus einer normalen Download-Statistik (Bsp: "[23/Apr/2004:10:36:33 +0000]", wahlweise auch nur "[23/Apr/2004:10:36:33") parsen und in TDateTime umwandeln. Die Standardroutinen wie StrToDateTime scheinen das nicht zu schaffen, da man ihnen kein solches Format vorgeben kann. Ich bin mir sicher, dass ich was übersehe, weil es ja eine Möglichkeit geben muss, auch solche Strings zu konvertieren. Vielleicht wisst ihr mehr und könnt mir weiterhelfen?
Vielen lieben Dank! ~SMALLID |
Re: Datumsstring formatiert nach TDateTime
Hallo SMALLID,
StrToDateTime und Co. benutzen m.E. als Standard die lokalen Einstellungen. Die zu benutzenden Formateinstellungen kann man aber ändern. Siehe Hilfe: - Currency and date/time formatting variables - Unit SysUtils - StrToDateTime function Habe das selbst noch nie benutzt. Müsste aber funktionieren. Gib mal Feedback bei Erfolg. Gruss Geronimo |
Re: Datumsstring formatiert nach TDateTime
Hallo,
ich erinnere mich an diesen Thread: ![]() Vielleicht hilft es ein wenig. Grüße vom marabu |
Re: Datumsstring formatiert nach TDateTime
Hallo marabu,
Danke! Ich habe mir mit Hilfe dieses Threads was basteln können: Bsp.-string siehe oben: '[23/May/2006:19:22:45 '
Delphi-Quellcode:
function ParseDlDateTimeString(s : string) : TDateTime;
var fs : TFormatSettings; sl : TStringList; i : integer; date, time : string; begin //s := '[23/Apr/2004:20:08:33'; date := copy(s, 2, 11); //ShowMessage(date); time := copy(s, 14, 8); //ShowMessage(time); GetLocaleFormatSettings(GetUserDefaultLCID, fs); with fs do begin fs.ShortMonthNames[1] := 'Jan'; fs.ShortMonthNames[2] := 'Feb'; fs.ShortMonthNames[3] := 'Mar'; fs.ShortMonthNames[4] := 'Apr'; fs.ShortMonthNames[5] := 'May'; fs.ShortMonthNames[6] := 'Jun'; fs.ShortMonthNames[7] := 'Jul'; fs.ShortMonthNames[8] := 'Aug'; fs.ShortMonthNames[9] := 'Sep'; fs.ShortMonthNames[10] := 'Oct'; fs.ShortMonthNames[11] := 'Nov'; fs.ShortMonthNames[12] := 'Dec'; sl := TStringList.Create; sl.Delimiter := '/'; sl.DelimitedText := date; for i := 1 to 12 do if ShortMonthNames[i] = sl[1] then begin if i < 10 then sl[1] := '0' + IntToStr(i) else sl[1] := IntToStr(i); Break; end; date := Format('%s/%s/%s', [sl[0], sl[1], sl[2]]); sl.Free; fs.DateSeparator := '/'; fs.ShortDateFormat := 'dd/mm/yyyy'; fs.ShortTimeFormat := 'hh:mm:ss'; end; result := StrToDate(date, fs) + StrToTime(time, fs); end; //~~~~~~~~~~~~~~~~~~~~~~~~~ |
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:49 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz