办法果然行啊
又学了一招
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,DateUtils;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var D1,D2:TDateTime;
S:String;
iDay,iHour,iMinute,iSecond:Integer;
begin
D1:=strtodatetime('2007-10-24 12:13:21');
D2:=strtodatetime('2007-11-12 10:23:21');
iDay:=DaysBetween(D1,D2);
D1:=IncDay(D1,iDay);
iHour:=HoursBetween(D1,D2);
D1:=IncHour(D1,iHour);
iMinute:=MinutesBetween(D1,D2);
D1:=IncMinute(D1,iMinute);
iSecond:=SecondsBetween(D1,D2);
S:='相差'+inttostr(iDay)+'天';
S:=S+inttostr(iHour)+'小时';
S:=S+inttostr(iMinute)+'分';
S:=S+inttostr(iSecond)+'秒';
showmessage(S);
edit1.Text:=s;
end;
end.
结果:相差18天22小时10分0秒