Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   DateTime String Format nicht bekannt (https://www.delphipraxis.net/213556-datetime-string-format-nicht-bekannt.html)

TRomano 17. Aug 2023 10:01

DateTime String Format nicht bekannt
 
Hallo zusammen,

über eine Schnittstelle bekomme ich neuerdings Daten, deren Format ich noch nie gesehen hatte:

"Mon Jun 26 2023 07:20:48 GMT+0000 (Coordinated Universal Time)"

Kennt das jemand von Euch? Wenn ja, parst ihr das dann selber oder gibt es in Delphi platformunabhängige Versionen zum Umwandeln in TDateTime?
Diese Daten sollen in eine MariaDB als DateTime oder Timestamp gespeichert werden.

Danke im Voraus !

Tom

Bernhard Geyer 17. Aug 2023 10:58

AW: DateTime String Format nicht bekannt
 
Schaut nach US-Format aus mit Monat = Text und dafür das / als Erkennungsmerkmal weg gelassen.

TRomano 17. Aug 2023 12:32

AW: DateTime String Format nicht bekannt
 
Danke.
Das werde ich mal so versuchen.

himitsu 17. Aug 2023 13:39

AW: DateTime String Format nicht bekannt
 
Also für eine Schnittstelle ist das ja eher ein ungünstiges Format.

Sicher, dass die, wo das her komm, nicht 'nen Bug haben oder irgendwelche (hoffentlich vorübergehenden) Mist bauen?


Emba hat ja letztens an den Datums-Funktionen was repariert ... eventuell klappt es, wenn du dem StrToDateTime das
Delphi-Quellcode:
'ddd mmm dd yyyy hh:mm:ss'
gibst,
also
Delphi-Quellcode:
'ddd mmm dd yyyy'
im FormatSettings als DateStr und
Delphi-Quellcode:
'hh:mm:ss'
als TimeStr. (vorher ab 'GMT' alles entfernt)

Es wäre zu schön, wenn es ein eine Umkehrfunktion zum Delphi-Referenz durchsuchenFormatDateTime und Delphi-Referenz durchsuchenDateTimeToString gäbe.




PS:
Delphi-Quellcode:
procedure TForm25.FormCreate(Sender: TObject);
type
  TDayNames = array[1..7] of string;
  TMonNames = array[1..12] of string;
const
  DayNames: TDayNames = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
  MonNames: TMonNames = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
begin
  Caption := FormatDateTime('DDD MMM DD YYYY HH:MM:SS "GMT+0000 (Coordinated Universal Time)"', Now);

  // Warum hat Invarant im englischen Format die deutschen Namen?
  Caption := FormatDateTime('DDD MMM DD YYYY HH:MM:SS "GMT+0000 (Coordinated Universal Time)"', Now, TFormatSettings.Invariant);

  var FS := TFormatSettings.Invariant;
  TDayNames(FS.ShortDayNames)  := DayNames;
  TMonNames(FS.ShortMonthNames) := MonNames;
  Caption := FormatDateTime('DDD MMM DD YYYY HH:MM:SS "GMT+0000 (Coordinated Universal Time)"', Now, FS);
end;
Also oben beim StrToDateTime mit dem FormatSettings aufpassen.

Uwe Raabe 17. Aug 2023 13:59

AW: DateTime String Format nicht bekannt
 
Mit diesen FormatSettings sollte es mit TryStrToDateTime gehen. Allerdings bleibt die Zeitzone dabei unberücksichtigt und müsste von Hand ausgewertet werden.

Delphi-Quellcode:
  var fmt := TFormatSettings.Invariant;
  fmt.ShortDateFormat := 'ddd mmm dd yyyy';

  fmt.ShortDayNames[1] := 'Sun';
  fmt.ShortDayNames[2] := 'Mon';
  fmt.ShortDayNames[3] := 'Tue';
  fmt.ShortDayNames[4] := 'Wed';
  fmt.ShortDayNames[5] := 'Thu';
  fmt.ShortDayNames[6] := 'Fri';
  fmt.ShortDayNames[7] := 'Sat';

  fmt.ShortMonthNames[1] := 'Jan';
  fmt.ShortMonthNames[2] := 'Feb';
  fmt.ShortMonthNames[3] := 'Mar';
  fmt.ShortMonthNames[4] := 'Apr';
  fmt.ShortMonthNames[5] := 'May';
  fmt.ShortMonthNames[6] := 'Jun';
  fmt.ShortMonthNames[7] := 'Jul';
  fmt.ShortMonthNames[8] := 'Aug';
  fmt.ShortMonthNames[9] := 'Sep';
  fmt.ShortMonthNames[10] := 'Oct';
  fmt.ShortMonthNames[11] := 'Nov';
  fmt.ShortMonthNames[12] := 'Dec';

mytbo 17. Aug 2023 18:47

AW: DateTime String Format nicht bekannt
 
Zitat:

Zitat von TRomano (Beitrag 1525707)
"Mon Jun 26 2023 07:20:48 GMT+0000 (Coordinated Universal Time)"

Kennt das jemand von Euch?

Mit der mORMot Bibliothek so:
Delphi-Quellcode:
uses
  mormot.core.base,
  mormot.core.datetime;

const
  DATE_TIME = 'Mon Jun 26 2023 07:20:48 GMT+0000 (Coordinated Universal Time)';
begin
  var dt: TDateTime;
  if HttpDateToDateTime(DATE_TIME, dt) then
    ShowMessage(DateTimeToStr(dt));
Bis bald...
Thomas

himitsu 17. Aug 2023 21:04

AW: DateTime String Format nicht bekannt
 
Zitat:

Delphi-Quellcode:
HttpDateToDateTime(DATE_TIME, dt)

ach du sch....

Das ist wirklich ein echtes Datenaustauschformat?
Wer hat sich denn sowas Grauenhaftes ausgedacht und warum?

Bei Google suchenHttpDatetime
https://stackoverflow.com/questions/...e-code-c-sharp
...

Uwe Raabe 17. Aug 2023 21:28

AW: DateTime String Format nicht bekannt
 
Delphi-Quellcode:
HttpToDate
aus System.DateUtils leistet das übrigens auch.

mytbo 17. Aug 2023 21:33

AW: DateTime String Format nicht bekannt
 
Zitat:

Zitat von himitsu (Beitrag 1525756)
Wer hat sich denn sowas Grauenhaftes ausgedacht und warum?

Wer: RFC 7231

Bis bald...
Thomas

TRomano 18. Aug 2023 11:43

AW: DateTime String Format nicht bekannt
 
Super ! Danke für all eure Antworten!
War heute noch mit etwas Anderem beschäftigt, deshalb werde ich es erst heute Nachmittag probieren können.


Alle Zeitangaben in WEZ +1. Es ist jetzt 13:49 Uhr.
Seite 1 von 2  1 2      

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