Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Korrespondenz problem- StrToTime und TimeToStr (https://www.delphipraxis.net/110067-korrespondenz-problem-strtotime-und-timetostr.html)

Mr.borland 12. Mär 2008 13:53


Korrespondenz problem- StrToTime und TimeToStr
 
ich habe fogendes problem:

zu bestimmten ereignissen schreibe ich die zeit millisekunden genau in eine textdatei (wandle Time to string ) und später möchte ich statistik daruber führen (wandle string to time ). doch da passiert etwas nicht naturliches.

Delphi-Quellcode:
procedure TForm1.test2;
var t1,t2: TDateTime;
begin
  t1 := StrToTime('15:0:34,500', FormatSettings);  
  Caption := TimeToStr(t1,FormatSettings);  
  t2 := StrToTime(Caption, FormatSettings);  !!!! hier passiert der fehler. !!!!

end;
mir ist folgendes aufgefallen: StrToTime bekommt den string als 'hh:nn:ss,zzz' aber TimeToStr liefert mir einen string der 'hh:nn:ss:zzz' formatiert ist.
also korrespondieren die zwei funktionen nicht miteinander?!
woran liegt das?

mein FormatSettings sieht wie folgt aus:
Delphi-Quellcode:
  GetLocaleFormatSettings(LOCALE_USER_DEFAULT, FormatSettings);
  FormatSettings.TwoDigitYearCenturyWindow := 1;
  FormatSettings.DateSeparator := '.';
  FormatSettings.TimeSeparator := ':';
  FormatSettings.ShortTimeFormat := 'hh:nn';
  FormatSettings.LongTimeFormat := 'hh:nn:ss:zzz';
  FormatSettings.ShortDateFormat := '';
  FormatSettings.LongDateFormat := '';
danke für eure hilfe.

Tyrael Y. 12. Mär 2008 14:10

Re: Korrespondenz problem- StrToTime und TimeToStr
 
Zitat:

Zitat von Mr.borland
woran liegt das?

mein FormatSettings sieht wie folgt aus:
Delphi-Quellcode:
  GetLocaleFormatSettings(LOCALE_USER_DEFAULT, FormatSettings);
  FormatSettings.TwoDigitYearCenturyWindow := 1;
  FormatSettings.DateSeparator := '.';
  FormatSettings.TimeSeparator := ':';
  FormatSettings.ShortTimeFormat := 'hh:nn';
  FormatSettings.LongTimeFormat := 'hh:nn:ss:zzz'; // <- hier steht doch, dass du es so interpretiert haben willst
  FormatSettings.ShortDateFormat := '';
  FormatSettings.LongDateFormat := '';

Weil du es selbst angegeben hast ;)

Mr.borland 12. Mär 2008 14:28

Re: Korrespondenz problem- StrToTime und TimeToStr
 
Delphi-Quellcode:
var t1: TDateTime;

  t1 := StrToTime(TimeToStr(Now,FormatSettings), FormatSettings);

Den string denn mir TimeToStr schreibt kann ich nicht in wieder mit StrToTime in TDateTime umwandeln.
das meine ich mit korrespondez problem.

mein FormatSettings sieht immer noch wie folgt aus:
Delphi-Quellcode:
GetLocaleFormatSettings(LOCALE_USER_DEFAULT, FormatSettings);
  FormatSettings.TwoDigitYearCenturyWindow := 1;
  FormatSettings.DateSeparator := '.';
  FormatSettings.TimeSeparator := ':';
  FormatSettings.ShortTimeFormat := 'hh:nn';
  FormatSettings.LongTimeFormat := 'hh:nn:ss:zzz'; // <- hier steht doch, dass du es so interpretiert haben willst
  FormatSettings.ShortDateFormat := '';
  FormatSettings.LongDateFormat := '';

Der.Kaktus 12. Mär 2008 14:56

Re: Korrespondenz problem- StrToTime und TimeToStr
 
Hallo,

wirst wohl nicht drumrum kommen, Encode-/DecodeTime zu nutzen.


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:31 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