如题
如何得到datetime类型的年月日 时分秒的值

解决方案 »

  1.   

    dayof
    monthof
    yearof
    secondof
    ...
      

  2.   

    uses DateUtils;procedure TForm1.Button1Click(Sender: TObject);
    var
      AYear,AMonth,ADay,AHour,AMinute,ASecond,AMilliSecond:Word;
    begin
      DecodeDateTime(now,AYear,AMonth,ADay,AHour,AMinute,ASecond,AMilliSecond);
      label1.Caption:=floattostr(ayear);
      label2.Caption:=floattostr(AMonth);
      label3.Caption:=floattostr(ADay);
      label4.Caption:=floattostr(AHour);
      label5.Caption:=floattostr(AMinute);
      label6.Caption:=floattostr(ASecond);
      label7.Caption:=floattostr(AMilliSecond);
    end;
      

  3.   

    我前两天试了以下,用函数DayToStr
      

  4.   

    用gxgyj(杰克.逊) 和 jinjazz(近身剪(N-P攻略)) 说的函数
      

  5.   

    DecodeDateTime 函数是专门用于分解日期时间的。
      

  6.   

    用formatdatetime函数The following example uses FormatDateTime to set the string variable S to a sentence indicating a meeting time in 3 hours. The sentence has the form 'The meeting is on Wednesday, February 15, 1995 at 2:30 PM'. S := FormatDateTime('"The meeting is on " dddd, mmmm d, yyyy, " at " hh:mm AM/PM', Now + 0.125);
      

  7.   

    \\我写的一个日期处理单元
    unit DealDate;interface
    uses SysUtils;function DaysInMonth(ADate:TDateTime):Integer;
    function GetMonth(ADate:TDateTime):Integer;
    function GetDay(ADate:TDateTime):Integer;
    function GetYear(ADate:TDateTime):Integer;
    function Gethour(ADate:TDateTime):Integer;
    function Getminute(ADate:TDateTime):Integer;
    function Getsecond(ADate:TDateTime):Integer;implementationfunction GetMonth(ADate:TDateTime):Integer;
    var
      MyMonth,  MyYear,   MyDay : Word;
    begin
      DecodeDate(ADate, MyYear, MyMonth, MyDay);
      Result:=mymonth;
    end;function GetDay(ADate:TDateTime):Integer;
    var
      MyMonth,   MyYear,   MyDay : Word;
    begin
      DecodeDate(ADate, MyYear, MyMonth, MyDay);
      result:=myday;
    end;function GetYear(ADate:TDateTime):Integer;
    var
      MyMonth,  MyYear,  MyDay : Word;
    begin
      DecodeDate(ADate, MyYear, MyMonth, MyDay);
      result:=myyear;
    end;function Gethour(ADate:TDateTime):Integer;
    var
      Hour, Min, Sec, MSec: Word;
    begin
      DecodeTime(ADate, Hour, Min, Sec, MSec);
      result:=Hour;
    end;function Getminute(ADate:TDateTime):Integer;
    var
      Hour, Min, Sec, MSec: Word;
    begin
      DecodeTime(ADate, Hour, Min, Sec, MSec);
      result:=Min;
    end;function GetSecond(ADate:TDateTime):Integer;
    var
      Hour, Min, Sec, MSec: Word;
    begin
      DecodeTime(ADate, Hour, Min, Sec, MSec);
      result:=sec;
    end;function DaysInMonth(ADate:TDateTime):Integer;
    var
      MyMonth,
      MyYear,
      MyDay : Word;
      tmpBool : Boolean;
    begin
      DecodeDate(ADate, MyYear, MyMonth, MyDay);
      tmpBool := IsLeapYear(MyYear);
      case mymonth of
      1,3,5,7,8,10,12 :result:=31;
      4,6,9,11        :result:=30;
      2               :
        begin
          if TmpBool then
            result:=29
          else
            result:=28
        end;
      end;
    end;
    end.