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

2025-04-09 00:15:55
推荐回答(3个)
回答(1):

var
CurrTime:string;

CurrTime := FormatDateTime('HHMM',Now);
if (CurrTime >= '0800') and (CurrTime < '1200') then
begin
//在设定的8点到12点这个时间段
end
else
begin
//不在设定的8点到12点这个时间段
end;

回答(2):

直接用当前时间与规定时间进行比较就可以了。
取得当前日期函数date.
if (date>DateTimePicker1.date) and (date Begin
end;
如果是字符型的日期格式,可以转换一下。
if (date>StrToDate(strdate1) ) and (date Begin
end;

回答(3):

恩,楼上的没错
变红就是shape1.color:=clred;
变绿就是shape1.color:=clgreed;