delphi 判断当前时间是不是在规定的时间段

首先获取当前时间,然后判断是不是在我设定的8点到12点这个时间段,是则使shape变绿色,不是则变红。

第1个回答  推荐于2018-03-11
var
CurrTime:string;

CurrTime := FormatDateTime('HHMM',Now);
if (CurrTime >= '0800') and (CurrTime < '1200') then
begin
//在设定的8点到12点这个时间段
end
else
begin
//不在设定的8点到12点这个时间段
end;本回答被提问者和网友采纳
第2个回答  推荐于2016-10-19
直接用当前时间与规定时间进行比较就可以了。
取得当前日期函数date.
if (date>DateTimePicker1.date) and (date<DateTimePicker.2date) then
Begin
end;
如果是字符型的日期格式,可以转换一下。
if (date>StrToDate(strdate1) ) and (date<StrToDate(strdate2) ) then
Begin
end;
第3个回答  2010-10-08
恩,楼上的没错
变红就是shape1.color:=clred;
变绿就是shape1.color:=clgreed;