例如 var a:TdateTime;// begin a:=....//a以前的值 ... (now -a)*86400//86400为一天的秒数end; 根据这个秒数换算成小时,分秒
function ToTime(DateTime:TDateTime;day,hour,minute,second:{加减量}integer):TDateTime; {给出一个具体时间,减去天数或小时、分钟、秒钟,即得到新时间} var hh,mm,ss,ms:word; hx,mx,sx:integer; {时间中间值} dt:TDate; begin dt :=DateTime; DecodeTime(DateTime,hh,mm,ss,ms); hx:=hh; mx:=mm; sx:=ss; {秒} sx:=sx+second; if sx<0 then begin minute :=minute + (sx div 60)-1; sx :=60 +(sx mod 60); end else if sx>=60 then begin minute :=minute+(sx div 60); sx :=sx mod 60; end; {分} mx :=mx+minute; if mx<0 then begin hour :=hour+(mx div 60)-1; mx :=60+(mx mod 60); end else if mx>=24 then begin hour :=hour+(mx div 60); mx :=mx mod 60; end; {时} hx :=hx+hour; if hx<0 then begin day :=day+(hx div 24)-1; hx :=24+(hx mod 24); end else if hx>=24 then begin day :=day+(hx div 24); hx :=hx mod 24; end; {天} dt :=dt+day; DateTime :=StrToDateTime(DateToStr(dt)+' '+IntToStr(hx)+':'+IntToStr(mx)+ ':'+IntToStr(sx)+':'); Result :=DateTime; end; 这是尚在编制中的源码,求两个时间差:天数、小时、分钟等。
专门处理时间计算,时间的判断
var
a:TdateTime;//
begin
a:=....//a以前的值
...
(now -a)*86400//86400为一天的秒数end;
根据这个秒数换算成小时,分秒
{给出一个具体时间,减去天数或小时、分钟、秒钟,即得到新时间}
var
hh,mm,ss,ms:word;
hx,mx,sx:integer; {时间中间值}
dt:TDate;
begin
dt :=DateTime;
DecodeTime(DateTime,hh,mm,ss,ms);
hx:=hh;
mx:=mm;
sx:=ss;
{秒}
sx:=sx+second;
if sx<0 then
begin
minute :=minute + (sx div 60)-1;
sx :=60 +(sx mod 60);
end
else if sx>=60 then
begin
minute :=minute+(sx div 60);
sx :=sx mod 60;
end;
{分}
mx :=mx+minute;
if mx<0 then
begin
hour :=hour+(mx div 60)-1;
mx :=60+(mx mod 60);
end
else if mx>=24 then
begin
hour :=hour+(mx div 60);
mx :=mx mod 60;
end;
{时}
hx :=hx+hour;
if hx<0 then
begin
day :=day+(hx div 24)-1;
hx :=24+(hx mod 24);
end
else if hx>=24 then
begin
day :=day+(hx div 24);
hx :=hx mod 24;
end;
{天}
dt :=dt+day;
DateTime :=StrToDateTime(DateToStr(dt)+' '+IntToStr(hx)+':'+IntToStr(mx)+
':'+IntToStr(sx)+':');
Result :=DateTime;
end;
这是尚在编制中的源码,求两个时间差:天数、小时、分钟等。