var
 SectionOneStart,SectionOneEnd:string;
 TempCurrentDateTime:TTime;
begin
 SectionOneStart:='8:00:00';
 SectionOneEnd:='12:00:00';
 TempCurrentDateTime:=Now();
 if (StrToTime(SectionOneStart)< TempCurrentDateTime) then
 showmessage(timetostr(TempCurrentDateTime)+'  '+SectionOneStart);
 if StrToTime(SectionOneEnd)<TempCurrentDateTime then
    showmessage(timetostr(TempCurrentDateTime)+'  '+SectionOneEnd);
把机器时间跳到8:00-12:00之间,告诉我什么结果

解决方案 »

  1.   

    楼主你加个变量t,然后逐步跟踪取t的值看看就知道了。如下:t := StrToTime(SectionOneStart);
    t := StrToTime(SectionOneEnd);
      

  2.   

    还有,这是delphi送给你的例子:procedure TForm1.Button1Click(Sender: TObject);var
      ATime: TDateTime;
    begin
      ATime := StrToTime(Edit1.Text);
      if ATime < 0.50 then
        ShowMessage('Good Morning')
      else
        ShowMessage('Good Afternoon');
    end;
      

  3.   

    //TDateTime类型本身属于浮点数,单位为天,即整数部分的值为距离1899年12月30日的天数
     //所以当只能时间赋值之后,因为没有日期部分,即整数部分为零,
     //那么也就是1899年12月30日的时间,当然与当前日期时间比较会有意想不到的结果。
     //所以在楼主的应用应当用当前的日期才是,故而应该加上取当前日期再加上时间。
     //TmpDateTime:=Int(Now())+StrToTime('08:00:00');var
     SectionOneStart,SectionOneEnd:string;
     TempCurrentDateTime:TTime;
    begin
     SectionOneStart:='8:00:00';
     SectionOneEnd:='12:00:00';
     TempCurrentDateTime:=Now();
     //if (StrToTime(SectionOneStart)< TempCurrentDateTime) then
     if ((StrToTime(SectionOneStart)+Int(TempCurrentDateTime){取整数部分,即日期})< TempCurrentDateTime) then
     showmessage(timetostr(TempCurrentDateTime)+'  '+SectionOneStart);
     //if StrToTime(SectionOneEnd)<TempCurrentDateTime then
     if (StrToTime(SectionOneEnd)+Int(TempCurrentDateTime))<TempCurrentDateTime then
        showmessage(timetostr(TempCurrentDateTime)+'  '+SectionOneEnd);