我有,请楼主给分吧。昨天还在写的:此函数来自于杜宝大俠,我只是进行了一些修改。
function TFun.DateTimeDiff(St, Et: TDateTime): string;
var
SYear, SMonth, SDay, SHour, SMin, SSec, SMSec: Word
// ¿ªÊ¼Ê±¼ä
EYear, EMonth, EDay, EHour, EMin, ESec, EMSec: Word
// ½áÊøʱ¼ä
DYear, DMonth, DDay, DHour, DMin, DSec, DMSec: Integer
// ʱ²î
EDate: TDateTime
// Öмä±äÁ¿
{ i: Integer
// Öмä±äÁ¿£¬¼Ç¼ʱ²î¼ä¸ô¡£}
Y, M, D, H, N, S {, MS}: Word;
procedure InitVars;
begin
DecodeDateTime(EDate, EYear, EMonth, EDay, EHour, EMin, ESec, EMSec);
end;
begin
if St > Et then // ²ÎÊý³ö´í
begin
EDate := St
// ½»»»Æðֹʱ¼ä
St := Et;
Et := EDate;
end;
// ±äÁ¿³õʼ»¯¡£
DecodeDateTime(St, SYear, SMonth, SDay, SHour, SMin, SSec, SMSec);
EDate := Et;
InitVars;
// ½øλµÄ¼Ó¼õ£¬²»×ãÔò½èλ¡£
// ´Ó×îµÍλ¿ªÊ¼£¬ÏÈÀ´ºÁÃëλ£º
DMSec := EMSec - SMSec
// È¡ºÁÃëλ²î
if DMSec < 0 then
begin
DMSec := 1000 + DMSec;
EDate := IncSecond(EDate, -1)
// &frac12;è&Icirc;&raquo;
InitVars
// &cedil;&Auml;±&auml;&Aacute;&iquest;
end;
DSec := ESec - SSec
// &Egrave;&iexcl;&Atilde;&euml;&Icirc;&raquo;&sup2;&icirc;
if DSec < 0 then
begin
DSec := 60 + DSec;
EDate := IncMinute(EDate, -1);
InitVars;
end;
DMin := EMin - SMin
// &Egrave;&iexcl;·&Ouml;&Ouml;&Oacute;&sup2;&icirc;
if DMin < 0 then
begin
DMin := 60 + DMin;
EDate := IncHour(EDate, -1);
InitVars;
end;
DHour := EHour - SHour
// &Egrave;&iexcl;&ETH;&iexcl;&Ecirc;±&sup2;&icirc;
if DHour < 0 then
begin
DHour := 24 + DHour;
EDate := IncDay(EDate, -1);
InitVars;
end;
DDay := EDay - SDay
// &Egrave;&iexcl;&Igrave;ì&sup2;&icirc;&pound;&not;&Otilde;&acirc;&Agrave;&iuml;&frac34;&Iacute;&cedil;&acute;&Ocirc;&Oacute;&Aacute;&Euml;&pound;&iexcl;
if DDay < 0 then
begin
DDay := DaysInMonth(SDay) - SDay + EDay
// &micro;&frac12;&Ocirc;&Acirc;&micro;×&Ocirc;&Ugrave;&frac14;&Oacute;
EDate := IncMonth(EDate, -1);
InitVars;
end;
DMonth := EMonth - SMonth
// &Egrave;&iexcl;&Ocirc;&Acirc;&sup2;&icirc;
if DMonth < 0 then
begin
DMonth := 12 + DMonth;
EDate := IncYear(EDate, -1);
InitVars;
end;
DYear := EYear - SYear
// &Egrave;&iexcl;&Auml;ê&sup2;&icirc;
Assert(DYear >= 0, '&Oacute;&brvbar;&cedil;&Atilde;&sup2;&raquo;&iquest;&Eacute;&Auml;&Uuml;&ETH;&iexcl;&Oacute;&Uacute;0&pound;&iexcl;');
Y := DYear
M := DMonth
D := DDay;
H := DHour
N := DMin
S := DSec
{ MS := DMSec;}
if Y > 0 then Result := IntToStr(Y) + '&Auml;ê'
else if M > 0 then Result := IntToStr(M) + '&Ocirc;&Acirc;'
else if D > 0 then Result := IntToStr(D) + '&Igrave;ì'
else if H > 0 then Result := IntToStr(H) + '&ETH;&iexcl;&Ecirc;±'
else if N > 0 then Result := IntToStr(N) + '·&Ouml;&Ouml;&Oacute;'
else Result := IntToStr(S) + '&Atilde;&euml;';
end;
{-----------------------------------------------------------------------------
原来的函数
-----------------------------------------------------------------------------}
function TFun.De2DateTime(const St, Et: TDateTime): string;
const
Fmt = 相差%d 年 %d 月 %d 日 %d 小时 %d 分%d 秒 %d 毫秒';
var
//&Ograve;&Ocirc;&Iuml;&Acirc;±&auml;&Aacute;&iquest;&pound;&not;S&iquest;&ordf;&Ecirc;&frac14;&micro;&Auml;&Icirc;&ordf;&iquest;&ordf;&Ecirc;&frac14;&Ecirc;±&frac14;&auml;&pound;&not;E&iquest;&ordf;&Ecirc;&frac14;&micro;&Auml;&Icirc;&ordf;&frac12;á&Ecirc;&oslash;&Ecirc;±&frac14;&auml;&iexcl;&pound;
SYear, EYear, SMonth, EMonth, SDay, EDay: Word;
SHour, EHour, SMin, EMin, SSec, ESec, SMSec, EMSec: Word;
EDate: TDateTime
//&AElig;&eth;&iexcl;&cent;&Ouml;&Aacute;&Ecirc;&yacute;&frac34;&Yacute;&pound;&not;&Ouml;&raquo;&Ecirc;&Ccedil;&acute;&laquo;&Egrave;&euml;&sup2;&Icirc;&Ecirc;&yacute;&sup2;&raquo;&Ecirc;&Ccedil;Var&micro;&Auml;&pound;&not;×&ouml;&Ouml;&ETH;&frac14;&auml;±&auml;&Aacute;&iquest;&Oacute;&Atilde;&iexcl;&pound;
DYear, DMonth, DDay, DHour, DMin, DSec, DMSec: Integer
//&Ecirc;±&sup2;&icirc;&iexcl;&pound;
I: Integer
//&Ouml;&ETH;&frac14;&auml;±&auml;&Aacute;&iquest;&pound;&not;&frac14;&Ccedil;&Acirc;&frac14;&Ecirc;±&sup2;&icirc;&frac14;&auml;&cedil;&ocirc;&iexcl;&pound;
//&Ouml;&ETH;&frac14;&auml;&sup1;&yacute;&sup3;&Igrave;&pound;&not;&sup3;&otilde;&Ecirc;&frac14;±&auml;&Aacute;&iquest;&iexcl;&pound;
procedure InitVars;
begin
DeCodeDate(EDate, EYear, EMonth, EDay);
DeCodeTime(EDate, EHour, EMin, ESec, EMSec);
end;
begin
if St > Et then //&sup2;&Icirc;&Ecirc;&yacute;&sup3;&ouml;&acute;í&iexcl;&pound;
begin
Result := 'Error!';
Exit;
end;
{ ±&auml;&Aacute;&iquest;&sup3;&otilde;&Ecirc;&frac14;&raquo;&macr;&iexcl;&pound;
DYear:=0 ;DMonth:=0;DDay:=0;DHour:=0;DMin:=0;DSec:=0;DMSec:=0;}
EDate := Et;
DeCodeDate(St, SYear, SMonth, SDay);
DeCodeTime(St, SHour, SMin, SSec, SMSec);
InitVars;
//&frac12;&oslash;&Icirc;&raquo;&micro;&Auml;&frac14;&Oacute;&frac14;&otilde;&iexcl;&pound;&acute;&Oacute;×&icirc;&micro;&Iacute;&Icirc;&raquo;&iquest;&ordf;&Ecirc;&frac14;&pound;&iexcl;
//&Iuml;&Egrave;&Agrave;&acute;&ordm;&Aacute;&Atilde;&euml;&Icirc;&raquo;&pound;&ordm;
DMSec := EMSec - SMSec
//&Egrave;&iexcl;&ordm;&Aacute;&Atilde;&euml;&Icirc;&raquo;&sup2;&icirc;
if DMSec < 0 then //&sup2;&raquo;×&atilde;&Oacute;&brvbar;&cedil;&Atilde;&frac12;è&Icirc;&raquo;
begin
DMSec := 1000 + DMSec;
EDate := IncSecond(EDate, -1)
//&frac12;è&Icirc;&raquo;&iexcl;&pound;
InitVars
//&cedil;&Auml;±&auml;&Aacute;&iquest;&iexcl;&pound;
end;
DSec := ESec - SSec
//&Egrave;&iexcl;&Atilde;&euml;&Icirc;&raquo;&sup2;&icirc;
if DSec < 0 then
begin
DSec := 60 + DSec;
EDate := IncMinute(EDate, -1);
InitVars;
end;
DMin := EMin - SMin
//&Egrave;&iexcl;·&Ouml;&Ouml;&Oacute;&sup2;&icirc;
if DMin < 0 then
begin
DMin := 60 + DMin;
EDate := IncHour(EDate, -1);
InitVars;
end;
DHour := EHour - SHour
//&Egrave;&iexcl;&ETH;&iexcl;&Ecirc;±&sup2;&icirc;
if DHour < 0 then
begin
DHour := 24 + DHour;
EDate := IncDay(EDate, -1);
InitVars;
end;
//**********************************************
//&cedil;&Auml;&pound;&ordm;
DDay := EDay - SDay
//&Egrave;&iexcl;&Igrave;ì&sup2;&icirc;&pound;&not;&Otilde;&acirc;&Agrave;&iuml;&frac34;&Iacute;&cedil;&acute;&Ocirc;&Oacute;&Aacute;&Euml;&pound;&iexcl;
if DDay < 0 then
begin
DDay := DaysInMonth(SDay) - SDay + EDay
//&micro;&frac12;&Ocirc;&Acirc;&micro;×&pound;&not;&Ocirc;&Ugrave;&frac14;&Oacute;
EDate := IncMonth(EDate, -1);
InitVars;
end;
{ &Ocirc;&shy;&Iuml;&Egrave;&micro;&Auml;&Ecirc;&Ccedil;&acute;í&micro;&Auml;
******************************************
DDay := EDay - SDay;//&Egrave;&iexcl;&Igrave;ì&sup2;&icirc;&pound;&not;&Otilde;&acirc;&Agrave;&iuml;&frac34;&Iacute;&cedil;&acute;&Ocirc;&Oacute;&Aacute;&Euml;&pound;&iexcl;
if DDay < 0 then
begin
while DDay < 0 do
begin
i:= DaysBetween(EDate , IncMonth(EDate,-1));//&Egrave;&iexcl;&micro;±&Ocirc;&Acirc;&Igrave;ì&Ecirc;&yacute;
DDay := i + DDay;
EDate :=IncMonth(EDate,-1);
end;
InitVars;
end;
***************************************
}
DMonth := EMonth - SMonth;
if DMonth < 0 then
begin
DMonth := 12 + DMonth;
EDate := IncYear(EDate, -1);
InitVars;
end;
DYear := EYear - SYear;
if DYear < 0 then
begin
Result := 'Error!';
Exit;
end;
Result := Format(Fmt, [DYear, DMonth, DDay, DHour, DMin, DSec, DMSec]);
end;
注意一下,乱码是注释用的中文。你可以直接复制到编辑器,去掉了就行了。