procedure TForm1.Button1Click(Sender: TObject);
var
a,b:Tdatetime;
year,month,day,hour,minute,second,msecond:word;
year1,month1,day1,hour1,minute1,second1,msecond1:word;
begin
a:=strtodatetime('2002-6-12 12:12:12');
b:=strtodatetime('2002-7-7 12:13:13');
decodedate(a,year,month,day);
decodetime(a,hour,minute,second,msecond);
decodetime(b,hour1,minute1,second1,msecond1);
decodedate(b,year1,month1,day1);
if msecond1<msecond then
begin
msecond1:=msecond1+1000;
second1:=second1-1;
end;
if second1<second then
begin
second1:=second1+60;
minute1:=minute1-1;
end;
if minute1<minute then
begin
minute1:=minute1+60;
hour1:=hour1-1;
end;
if hour1<hour then
begin
hour1:=hour1+24;
day1:=day1-1;
end;
if day1<day then
begin
if month1 in [1,3,5,7,8,10,12] then
day1:=day1+31
else if month1 in [4,6,9,11] then
day1:=day1+30
else if month1 = 2 then
begin
if year1 div 4 =year1/4 then
day1:=day1+29
else
day1:=day1+28;
end;
month1:=Month1-1;
end;
if month1<month then
begin
month1:=month1+12;
year1:=year1-1;
end;
if year1<year then
ShowMessage('得到的结果为负数!');
edit1.text:=intTostr(year1-year)+'年'+intTostr(month1-month)+'月'+intTostr(day1-day)+'日'+intTostr(hour1-hour)+'时'+intTostr(minute1-minute)+'分'+intTostr(second1-second)+'秒'+IntToStr(Msecond1-msecond)+'毫秒';
end;
end.