怎么样判断一个时间在某两个时间范围内? 在线,立即结贴~~~~~(100分)

  • 主题发起人 主题发起人 tommy_linux
  • 开始时间 开始时间
T

tommy_linux

Unregistered / Unconfirmed
GUEST, unregistred user!
s1:='12:00:00'
s2:='14:00:00'
s:=strtotime(now);
可否这样做判断:if s>s1 and s<s2 then

不行的???该如何做?
 
应该有比较时间的function的,不过我现在手边没文档无法帮你查.你可以查查帮助.
 
必须变为日期型才能比较
if (strtotime(s1)>now) and (strtotime(s2)<now) then

//忘了(),不好意思
 
s1:='12:00:00'
s2:='14:00:00'
s:=FormatDateTime('hh:nn:ss',now);
if (s>s1) and (s<s2) then
……
 
Delphi7中通过
procedure TForm1.Button1Click(Sender: TObject);
const
s1 = '11:12:0';
begin
if (StrToTime(s1) > StrToTime('5:0:0')) and (StrToTime(s1) <= StrToTime('12:0:0')) then
showmessage('yes');
end;
 
既然是时间了,注意不要用StrToDateTime(),它要求一个日期时间的字串,
用StrToTime()就行了。
上两层的朋友说过了。
但是很遗憾的是,它转换出来的并不能和 now 相比,now 是 TDateTime 类型,
而这个是 TTime 类型。
 
已经解决~~~~~~

TDateTime本质是浮点类型,所以可以这样比较。
var
s,s1,s2:TdateTime;
begin
s1:=strtotime('12:00:00');
s2:=strtotime('14:00:00');
s := now;
s := s - Trunc(s);
if (s>s1) and (s<s2) then
...
end;

谢谢你们的参与~~~~~~~~~~~
 
后退
顶部