如果计算两个时间点之间的秒数。我想来想去如果说要写出个没有bug的代码实在太复杂了首先考虑分钟的度过不能直接用TDateTime得到的秒数直接相减在扩展问题如果两个分钟正在两个小时之间同样两天之间的转换两个星期两个月两个年... .怎么样是不又很复杂。软件要写的没有毛病真的要多下功夫了。vc中可以通过time函数得到1970年至今的秒数在delphi中也能得到这个秒数么用什么办法
解决方案 »
- 哪位大大用过win7的?请说一下感受
- ado 赋值 的问题
- 线程同步问题,连续使用了两个Synchronize,第二个怎么也不执行???
- 关于窗口的隐藏与显示
- 求:delphi5开发人员指南附带光盘里面的第34章:客户跟踪系统,midas开发源代码。
- 对两个表进行操作,怎样保持两个表的一致性?
- x=class(x1,x2,x3,x4..)是表示x继承了x1,x2,x3,x4等的类吗?最好用典型的事例来说明
- 能写几个简单的访问本地数据库的sql语句吗.谢谢
- 救急!!!!为何我的BDE ADMINISTATOR 无法运行???
- 如何定位一个字符在字符串中位置 ???
- fastreport中,如何知道打10条记录纸张高度是多少?
- (在线等待...)用ClientDataSet1怎样从COM服务器(用SocketConnection1连接的)下载数据到本在保存为*.CDS......
const ASeconds: Int64): Boolean;用函数WithinPastSeconds,delphi6在
UnitDateUtilsCategorydate/time routinesfunction WithinPastSeconds(const ANow, AThen: TDateTime; const ASeconds: Int64): Boolean;DescriptionCall WithinPastSeconds to determine whether the date and time specified by ANow is within ASeconds seconds of the date and time specified by AThen. Note: WithinPastSeconds uses the SecondsBetween function, which means that fractional seconds do not count. If ANow and AThen are 2 and a half seconds apart, calling WithinPastSeconds with ASeconds set to 2 returns True.
2.75 1/1/1900 6:00 pm
-1.25 12/29/1899 6:00 am
35065 1/1/1996 12:00 am
secondOf(T1)-SecondOf(T2) 返回T1和t2之是的秒数
如:T2:=‘1999-2-3 12:34:56:78’
T1:=‘1999-2-3 12:35:59:45’
返回3
D1,D2: TDateTime;
begin
if D1 >= D2 then
result := Trunc( (D1-D2)*24*60*60 )
else
result := Trunc( (D2-D1)*24*60*60 );
end;
var
Dat1,Dat2: TDatetime;
begin
dat1 := Strtodatetime('2005-02-02 12:11:11');
dat2 := Strtodatetime('2001-11-22 21:43:11');
Showmessage(Formatdatetime('yy"-""-"dd" "hh:mm:ss', dat1 - dat2));
//你要转为秒的话,再换算一下就是了
end;
Function SecondSpan(ANow, AThen); Double;函数,然后用Round()函数取出上面函数的四舍五入的值就可以了。
用你的那个函数求Datetime1和Datetime2之间相差的秒数,怎么有时候少了一秒?
规律好像是:当(t1-t2)*24*3600=***.999***时少一秒
当(t1-t2)*24*3600=***.000***时正确
查看函数定义为:C:\Program Files\Borland\Delphi7\Source\Rtl\Common\DateUtils.pas
function SecondsBetween(const ANow, AThen: TDateTime): Int64;
begin
Result := Trunc(SecondSpan(ANow, AThen));
end;
错误,应该用round()取整。