Thema: Zeitcode

Einzelnen Beitrag anzeigen

Dilom

Registriert seit: 25. Jul 2018
5 Beiträge
 
#25

AW: Zeitcode

  Alt 26. Jul 2018, 14:40
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.


Danke. : Başparmak:
  Mit Zitat antworten Zitat