关于时间的问题(20分)

  • 主题发起人 主题发起人 冰冰
  • 开始时间 开始时间

冰冰

Unregistered / Unconfirmed
GUEST, unregistred user!
请问怎样判断时间落在19:00和01:00之间?
 
19:00=<x<=23:59 or 0:00<=x>=01:00
 
if ((strtotime(timetostr(date))>=strtotime('19:00'))
and (strtotime(timetostr(date))<=strtotime('23:59')))
or ((strtotime(timetostr(date))>=strtotime('0:00'))
and (strtotime(timetostr(date))<=strtotime('1:00')))
then label1.Caption:='在' else label1.Caption:='不在';
 
function IsInTime(xTime: TDateTime; Hour1, Min1, Hour2, Min2: Integer): Boolean;
var
xHour, xMin, xSec, xMSec: Word;
begin
DecodeTime(xTime, xHour, xMin, xSec, xMSec); // this Procedure is declared in SysUtils
if (Hour2 < Hour1) or ((Hour2 = Hour1) and (Min2 < Min1)) then Inc(Hour2, 24);
Hour1:= Hour1 * 60 + Min1;
Hour2:= Hour2 * 60 + Min2;
xHour:= xHour * 60 + xMin;
Result:= (xHour >= Hour1) and (xHour <= Hour2);
end;
 
后退
顶部