AGB  ·  Datenschutz  ·  Impressum  







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

Zeitcode

Ein Thema von Dilom · begonnen am 25. Jul 2018 · letzter Beitrag vom 27. Jul 2018
 
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#18

AW: Zeitcode

  Alt 25. Jul 2018, 18:29
FormatSettings hat gefehlt, so klappt es, ich habe es getestet mit Delphi 2009.
Delphi-Quellcode:
function GetMillisecondSpan(S1, S2: String): Int64;
var
  t1, t2: TDateTime;
  FS: TFormatSettings;
begin
  GetLocaleFormatSettings(LOCALE_SYSTEM_DEFAULT, FS);
  FS.DecimalSeparator := '.';
  FS.TimeSeparator := ':';
  FS.LongTimeFormat := 'hh:nn:ss.zzz';
  try
    t1 := StrToTime(S1, FS);
    t2 := StrToTime(S2, FS);
  finally
    Result := MilliSecondsBetween(t1, t2);
  end;
end;

procedure TForm1.DurationClick(Sender: TObject);
begin
  Duration.Text := IntToStr(GetMillisecondSpan('01:23:45.678', '01:23:45.901'));
end;
In diesem Beispiel ist Duration.Text = 223

Delphi-Quellcode:
function GetDateTimeSpan ( S1, S2: String ): TDateTime;
var
  t1, t2: TDateTime;
  FS: TFormatSettings;
begin
  GetLocaleFormatSettings(LOCALE_SYSTEM_DEFAULT, FS);
  FS.DecimalSeparator := '.';
  FS.TimeSeparator := ':';
  FS.LongTimeFormat := 'hh:nn:ss.zzz';
  try
    t1 := StrToTime(S1, FS);
    t2 := StrToTime(S2, FS);
  finally
    Result := MilliSecondsBetween(t1, t2) / (1000.0 * 86400);
  end;
end;

procedure TForm1.DurationClick(Sender: TObject);
var
  FS: TFormatSettings;
begin
  GetLocaleFormatSettings(LOCALE_SYSTEM_DEFAULT, FS);
  FS.DecimalSeparator := '.';
  FS.TimeSeparator := ':';
  FS.LongTimeFormat := 'hh:nn:ss.zzz';
  Duration.Text := TimeToStr(GetDateTimeSpan('01:23:45.678','01:23:45.901'), FS);
end;
In diesem Beispiel ist Duration.Text = 00:00:00.223

Ich hoffe nun ist dieser Thread zufriedenstellend erledigt.
Gruß vom KodeZwerg

Geändert von KodeZwerg (25. Jul 2018 um 20:00 Uhr)
  Mit Zitat antworten Zitat
 


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 15:52 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