delphi时间相减函数  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi时间相减函数


//时间相减函数
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;

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.11654901504517 seconds