from DateUtils.pas;{ YearSpan and MonthSpan are approximates, not exact but pretty darn close }
function YearSpan(const ANow, AThen: TDateTime): Double;
function MonthSpan(const ANow, AThen: TDateTime): Double;
function WeekSpan(const ANow, AThen: TDateTime): Double;
function DaySpan(const ANow, AThen: TDateTime): Double;
function HourSpan(const ANow, AThen: TDateTime): Double;
function MinuteSpan(const ANow, AThen: TDateTime): Double;
function SecondSpan(const ANow, AThen: TDateTime): Double;
function MilliSecondSpan(const ANow, AThen: TDateTime): Double;
function YearSpan(const ANow, AThen: TDateTime): Double;
function MonthSpan(const ANow, AThen: TDateTime): Double;
function WeekSpan(const ANow, AThen: TDateTime): Double;
function DaySpan(const ANow, AThen: TDateTime): Double;
function HourSpan(const ANow, AThen: TDateTime): Double;
function MinuteSpan(const ANow, AThen: TDateTime): Double;
function SecondSpan(const ANow, AThen: TDateTime): Double;
function MilliSecondSpan(const ANow, AThen: TDateTime): Double;
begin
Caption := FloatToStr(SecondSpan(StrToTime('9:58:30'), StrToTime('8:30:20'))); //5290
end;
function SecondsBetween(const ANow, AThen: TDateTime):
嘻嘻嘻没有括号不行嘻嘻嘻嘻 Caption := FloatToStr((9 * 60 * 60 + 58 * 60 + 30) - (8 * 60 * 60 + 30 * 60 + 20)); //5290
可以直接减。
1秒=1
不到就是小数了。
a,b,temp:string;
Seconds:integer;
begin
a := '9:58:30';
b := '8:30:20';
Temp := timetostr(strtotime(a) - strtotime(b));
edit1.Text := temp;
//adjust hour minute second
if copy(temp,2,1) = ':' then
begin
Seconds := strtoint(copy(temp,1,1))*3600;
temp := copy(temp,3,length(temp)-2);
end
else if copy(temp,3,1) = ':' then
begin
Seconds := Strtoint(copy(temp,1,2))*3600;
temp := copy(temp,4,length(temp)-3);
end; if copy(temp,2,1) = ':' then
begin
Seconds := Seconds + strtoint(copy(temp,1,1)) * 60;
temp := Copy(temp,3,length(temp)-2);
end
else if copy(temp,3,1) = ':' then
begin
Seconds := Seconds + strtoint(copy(temp,1,2))*60;
temp := copy(temp,4,length(temp)-3);
end;
seconds := Seconds + strtoint(temp);Seconds就是你想要的秒数,不过没有正负,在这之前最好先将大数放在前面,这样就知道所计算出来的时间秒数是在前面还是在后面!
祝你好运!
没有注意
^_^