我从数据库里面查询出一个时间值,在程序里面定义了一个TDateTime变量,可是取小时和分的时候老是不行,DELPHI里面怎么取出时间啊

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);var
      Present: TDateTime;
      Year, Month, Day, Hour, Min, Sec, MSec: Word;
     begin
      Present:= Now;
      DecodeDate(Present, Year, Month, Day);
      Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
        + IntToStr(Month) + ' of Year ' + IntToStr(Year);
      DecodeTime(Present, Hour, Min, Sec, MSec);
      Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '
        + IntToStr(Hour);
    end;
      

  2.   

    Uses  dateUtils
    HourOf(Time)
    MinuteOf(Time)
      

  3.   

    Uses  dateUtils
    HourOf(Time)
    MinuteOf(Time)
      

  4.   

    用decodedata
    和decodetime 两个函数啊
      

  5.   

    decodedata
    Returns Year, Month, and Day values for a TDateTime value.UnitSysUtilsCategorydatetime routinesDelphi syntax:procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);
    DescriptionThe DecodeDate procedure breaks the value specified as the Date parameter into Year, Month, and Day values. If the given TDateTime value has a negative (BC) year, the year, month, and day return parameters are all set to zero.
      

  6.   

    时间变量:DateTime:TDateTime;
         小时:Hour:Word;
          分:Min:Word;
          秒:Sec:Word;
        毫秒:MSec:Word;
      DecodeTime(DateTime, Hour, Min, Sec, MSec);
      

  7.   

    其实用个datetimetostr(day)就可以了.再用copy()函数取一下即可.
    (初学者,难免有错误,错了别怪我喔!)