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));