str:=formatdatetime(now,'yyyy-mm-dd hh:mm:ss');

解决方案 »

  1.   

    呵,反了,是:
    str:=formatdatetime('yyyy-mm-dd hh:mm:ss',now); 
      

  2.   

    to clacklin:
    我不是要获取当前日期时间,就是要把上述的日期时间字符串转换成那个格式另外:这是从邮件头中提取的日期时间,邮件的日期时间一般都是这个格式吗?
    会不会不同类型的mail server生成的格式不一样?
      

  3.   

    var
     d:tdatetime;
    begin
     d:=StrInternetToDateTime(Tue, 7 Aug 2001 17:52:16 +0800);
     edit2.Text:=formatdatetime('yyyy-mm-dd hh:mm:ss',d);
    end;
      

  4.   

    str:=formatdatetime('yyyy-mm-dd hh:mm:ss',StrInternetToDateTime('7 Aug 2001 17:52:16 +0800')); 我今天怎么老打错。:)
      

  5.   

    还记得要在uses加上: IdGlobal。
      

  6.   

    老大,我在单位的机器上没有delphi6,你帮我把这个单元里的函数实现贴出来的吧
    对了indy带源码吗
      

  7.   

    那太可惜了,delphi6对日期函数的支持几乎是十分全面了,你想要的几乎都有。
    indy是有源码的,在Delphi6\Source\Indy下,我可无法完全从中摘出这个函数的代码,只能简单搞一下了。
    function RawStrInternetToDateTime(var Value: string): TDateTime;
    var
      i: Integer;
      Dt, Mo, Yr, Ho, Min, Sec: Word;
      sTime: string;
    begin
      Result := 0.0;
      Value := Trim(Value);
      if length(Value) = 0 then
      begin
        Exit;
      end;  try
        if StrToDay(Copy(Value, 1, 3)) > 0 then
        begin
          Fetch(Value);
        end;
        Dt := StrToIntDef(Fetch(Value), 1);
        Value := TrimLeft(Value);
        Mo := StrToMonth(Fetch(Value));
        Value := TrimLeft(Value);
        Yr := StrToIntDef(Fetch(Value), 1900);
        if Yr < 80 then
        begin
          Inc(Yr, 2000);
        end
        else
          if Yr < 100 then
        begin
          Inc(Yr, 1900);
        end;    Result := EncodeDate(Yr, Mo, Dt);
        Value := TrimLeft(Value);
        i := IndyPos(':', Value); {do not localize}
        if i > 0 then
        begin
          sTime := fetch(Value, ' '); {do not localize}
          Ho := StrToIntDef(Fetch(sTime, ':'), 0); {do not localize}
          Min := StrToIntDef(Fetch(sTime, ':'), 0); {do not localize}
          Sec := StrToIntDef(Fetch(sTime), 0);
          Result := Result + EncodeTime(Ho, Min, Sec, 0);
        end;
        Value := TrimLeft(Value);
      except
        Result := 0.0;
      end;
    end;
    function StrInternetToDateTime(Value: string): TDateTime;
    begin
      Result := RawStrInternetToDateTime(Value);
    end;
      

  8.   

    那你把Delphi6\Source\Indy\IdGlobal.pas拷到d5里,在程序里引用它,看能不能用呢?不然的话你就仔细看它的源代码,然后自己照着写一个。