AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Datumsstring formatiert nach TDateTime

Ein Thema von SMALLID · begonnen am 7. Mai 2007 · letzter Beitrag vom 7. Mai 2007
Antwort Antwort
SMALLID

Registriert seit: 10. Aug 2004
78 Beiträge
 
#1

Datumsstring formatiert nach TDateTime

  Alt 7. Mai 2007, 11:55
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
Muh
  Mit Zitat antworten Zitat
Geronimo

Registriert seit: 18. Dez 2006
Ort: Hamburg
38 Beiträge
 
#2

Re: Datumsstring formatiert nach TDateTime

  Alt 7. Mai 2007, 12:10
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
Die Welt ist rechteckig, linear und Gauss-verteilt!
  Mit Zitat antworten Zitat
marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#3

Re: Datumsstring formatiert nach TDateTime

  Alt 7. Mai 2007, 12:33
Hallo,

ich erinnere mich an diesen Thread: datumstring in datetime wandeln

Vielleicht hilft es ein wenig.

Grüße vom marabu
  Mit Zitat antworten Zitat
SMALLID

Registriert seit: 10. Aug 2004
78 Beiträge
 
#4

Re: Datumsstring formatiert nach TDateTime

  Alt 7. Mai 2007, 15:09
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;
//~~~~~~~~~~~~~~~~~~~~~~~~~
Muh
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:19 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz