DELPHI時間相減函式
阿新 • • 發佈:2019-01-28
//時間相減函式
procedure TimeMinus(StartTime,EndTime:string);
var
t,tmp:TDatetime;
d,h,n,s:integer;
str:string;
Begin
t:=abs(strtodatetime(EndTime)-strtodatetime(StartTime));
d:=round(t);
h:=round((t-d)*24);
tmp:=d+h/24;
n:=round((t-tmp)*1440);
tmp:=tmp+n/1440;
s:=round((t-tmp)*86400);
str:=inttostr(d)+'天'+inttostr(h)+'小時'+inttostr(n)+'分'+inttostr(s)+'秒';
{var
S1, S2: string;
Hour, Min, Sec, MSec: Word;
dtRepair: TDateTime;
begin
S1 := '2013-06-28 15:44:50';
S2 := '2013-06-28 16:47:51';
dtRepair := (StrToDateTime(mID[I].sEndTime) - StrToDateTime(mID[I].sBgnTime);
ShowMessage(Format('%.02d天%.02d小時%.02d分%.02d秒', [
Trunc(dtRepair),
Hour,
Min,
Sec
]);
end;
procedure TimeMinus(StartTime,EndTime:string);
var
t,tmp:TDatetime;
d,h,n,s:integer;
str:string;
Begin
t:=abs(strtodatetime(EndTime)-strtodatetime(StartTime));
d:=round(t);
h:=round((t-d)*24);
tmp:=d+h/24;
n:=round((t-tmp)*1440);
tmp:=tmp+n/1440;
s:=round((t-tmp)*86400);
str:=inttostr(d)+'天'+inttostr(h)+'小時'+inttostr(n)+'分'+inttostr(s)+'秒';
{var
S1, S2: string;
Hour, Min, Sec, MSec: Word;
dtRepair: TDateTime;
begin
S1 := '2013-06-28 15:44:50';
S2 := '2013-06-28 16:47:51';
dtRepair := (StrToDateTime(mID[I].sEndTime) - StrToDateTime(mID[I].sBgnTime);
ShowMessage(Format('%.02d天%.02d小時%.02d分%.02d秒', [
Trunc(dtRepair),
Hour,
Min,
Sec
]);
end;