请教:时间计算的问题?

ssoft 2003-10-19 08:14:29
字段类型为datetime,
格式为11:02:03

我想算出该时间的用秒计算的数值,
如果转化成string类型,
tottime:= strtofloat(copy(pdatetime,1,2))*3600+strtofloat(copy(pdatetime,4,2))*60+strtofloat(copy(pdatetime,7,2));

使用上述语句,却报错,
我分析原因是如果格式为00:00:01的话,
取到的值就有问题,

有没有ASP中的hour()类似的涵数?

在线等待!
...全文
94 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
huaneww 2003-10-19
  • 打赏
  • 举报
回复
同意楼上的看法,这样做比较理智!
空中居士 2003-10-19
  • 打赏
  • 举报
回复
原因可能是,字段类型为datetime,显示格式为11:02:03,但是存储的是一个数,应该先将其专存成字符,看看什么格式再处理。
idilent 2003-10-19
  • 打赏
  • 举报
回复
ShowMessage(FloatToStr(now()-StrToDateTime('2003-10-19 12:00:00 AM')));
outer2000 2003-10-19
  • 打赏
  • 举报
回复
uses dateutils;
procedure TForm1.Button1Click(Sender: TObject);
var
t:Tdatetime;
begin
t:=strtotime('11:01:01');
showmessage(inttostr(secondsbetween(t,0)));
end;
outer2000 2003-10-19
  • 打赏
  • 举报
回复
sorry,make a mistake;
Returns the number of seconds between two specified TDateTime values.

Unit

DateUtils

Category

datetime routines

Delphi syntax:

function SecondsBetween(const ANow, AThen: TDateTime): Int64;

C++ syntax:

extern PACKAGE __int64 __fastcall SecondsBetween(const System::TDateTime ANow, const System::TDateTime AThen);

Description

Call SecondsBetween to obtain the difference, in seconds, between two TDateTime values. SecondsBetween counts only entire seconds. Thus, SecondsBetween reports the difference between 9:00:00 AM and 9:00:00:999 AM as 0 because the difference is one millisecond short of an entire second.
outer2000 2003-10-19
  • 打赏
  • 举报
回复
Returns the second of the minute represented by a TDateTime value.

Unit

DateUtils

Category

datetime routines

Delphi syntax:

function SecondOf(const AValue: TDateTime): Word;

C++ syntax:

extern PACKAGE Word __fastcall SecondOf(const System::TDateTime AValue);

Description

Call SecondOf to obtain the second of the minute represented by a specified TDateTime value. SecondOf returns a value between 0 and 59.

Note: SecondOf returns the same value as the SecondOfTheMinute function.

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧