Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   [Codevorstellung ?] SecondsToTime - Multilanguage (https://www.delphipraxis.net/190844-%5Bcodevorstellung-%5D-secondstotime-multilanguage.html)

t.roller 14. Nov 2016 13:58

AW: [Codevorstellung ?] SecondsToTime - Multilanguage
 
Liste der Anhänge anzeigen (Anzahl: 1)
SecToTime: Lösungsvorschläge

Delphi-Quellcode:
function Floor(const X: Extended): Integer;
begin Result := Integer(Trunc(X)); if Frac(X) < 0 then Dec(Result); end;

function DurationHourMinSec1(Sec : Cardinal) : string;
var ZH, ZM, ZS : integer;
begin
ZH := Sec div 3600; ZM := Sec div 60 - ZH * 60; ZS := Sec - (ZH * 3600 + ZM * 60) ;
result:= Format('%.2d:%.2d:%.2d', [ZH, ZM, ZS]);
end;

function DurationHourMinSec2(Sec : Integer) : string;
var ZD, ZH, ZM, ZS : integer;
begin
ZD:= floor(sec div 3600 div 24);
ZH:= floor(sec div 3600 mod 24);
ZM:= floor(sec div 60 mod 60);
ZS:= floor(sec mod 60);
result:= Format('%.3dd:%.2dh:%.2dm:%.2ds', [ZD, ZH, ZM, ZS]);
end;

function DurationHourMinSec3(Sec : Integer) : string;
var ZD, ZH, ZM, ZS : integer;
begin
ZD:= floor(sec div 3600 div 24);
ZH:= floor(sec div 3600 mod 24);
ZM:= floor(sec div 60 mod 60);
ZS:= floor(sec mod 60);
result:= Format('%.3d days : %.2d hours : %.2d minutes : %.2d seconds', [ZD, ZH, ZM, ZS]);
end;

function DurationHourMinSec4(Sec : Integer) : string;
var ZD, ZH, ZM, ZS : integer;
begin
result:='';
ZD:= floor(sec div 3600 div 24);
ZH:= floor(sec div 3600 mod 24);
ZM:= floor(sec div 60 mod 60);
ZS:= floor(sec mod 60);
if ZD=0 then result:= Format('%.2d hours : %.2d minutes : %.2d seconds', [ZH, ZM, ZS]);
if (ZD=0) and (ZH=0) then result:= Format('%.2d minutes : %.2d seconds', [ZM, ZS]);
if (ZD=0) and (ZH=0) and (ZM=0) then result:= Format('%.2d seconds', [ZS]);
if result='' then
result:= Format('%.3d days : %.2d hours : %.2d minutes : %.2d seconds', [ZD, ZH, ZM, ZS]);
end;
...
Memo1.Lines.Add(DurationHourMinSec1(count));
Memo1.Lines.Add(DurationHourMinSec2(count));
Memo1.Lines.Add(DurationHourMinSec3(count));
Memo1.Lines.Add(DurationHourMinSec4(count));

Der schöne Günther 14. Nov 2016 14:28

AW: [Codevorstellung ?] SecondsToTime - Multilanguage
 
Viele Wege führen nach Rom? Alles klar, dieser hier auch 8-)

Delphi-Quellcode:
uses System.TimeSpan, Vcl.Dialogs;
var
   timeSpan: TTimeSpan;
begin
   timeSpan := TTimeSpan.FromSeconds(12345);
   ShowMessageFmt(
      '%d hours, %d minutes and %d seconds', [
      timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds
   ]);
end.


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:00 Uhr.
Seite 2 von 2     12   

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