如何将“20050901100105”转换成为DATETIME时间类型,急,在线等,请大家帮忙

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    const
      strDT = '20050901100105';
    var
      dt : TDateTime;
    begin
      dt := EncodeDateTime(StrToInt(Copy(strDT,1,4)),StrToInt(Copy(strDT,5,2)),
      StrToInt(Copy(strDT,7,2)),StrToInt(Copy(strDT,9,2)),
      StrToInt(Copy(strDT,11,2)),StrToInt(Copy(strDT,13,2)),0);
      Showmessage(DateTimetostr(dt));
    end;
      

  2.   

    function TForm1.CstrtoDatetime(Tstr: string): TDatetime;
    begin
      Result:=StrtoDatetime(Midstr(Tstr,1,4)+'-'+Midstr(Tstr,5,2)+'-'+Midstr(Tstr,7,2)+' '+Midstr(Tstr,9,2)+':'+Midstr(Tstr,11,2)+':'+Midstr(Tstr,13,2));
    end;