var str: String;str := FormatDateTime('YYYYMMDD',Now);

解决方案 »

  1.   

    str := FormatDateTime('YYYYMMDD',Strtodatetime('02-2-3'));
      

  2.   

    //我刚刚帮你写的
    Function TForm1.Split(ddatetime: Datetime): String;
    var
      i:integer;
      site:integer;
      tmp:string;
      Buf:String;
    begin
    Buf:=datetimetostr(ddatetime);
    site:=1;
    for i:=1 to length(buf) do
    begin
      if buf[i]='-'then
      begin
        tmp:=copy(buf,site,i-site);
        if length(tmp)=1 then
          tmp:='0'+tmp;
        Result:=Result+tmp;
        site:=i+1;
      end;
    end;
    tmp:=copy(buf,site,i);
    if length(tmp)=1 then
     tmp:='0'+tmp;
    Result:=Result+tmp;
    end;
    传入你的日期返回string
      

  3.   

    //我刚刚帮你写的
    Function TForm1.Split(ddatetime: Datetime): String;
    var
      i:integer;
      site:integer;
      tmp:string;
      Buf:String;
    begin
    Buf:=datetimetostr(ddatetime);
    site:=1;
    for i:=1 to length(buf) do
    begin
      if buf[i]='-'then
      begin
        tmp:=copy(buf,site,i-site);
        if length(tmp)=1 then
          tmp:='0'+tmp;
        Result:=Result+tmp;
        site:=i+1;
      end;
    end;
    tmp:=copy(buf,site,i);
    if length(tmp)=1 then
     tmp:='0'+tmp;
    Result:=Result+tmp;
    end;
    传入你的日期返回string
      

  4.   

    S := FormatDateTime('yyyy-mm-dd', StrToDate('02-2-3'));
    S := StringReplace(S, '-', '', [rfReplaceAll]);
      

  5.   

    datetimevarible:Tdatatime;s:=formatdatetime('yyyymmdd', datetimevarible);如果想将字符串转过去的话,就需要多一步:
    ShortDateFormat:='yyyy-mm-dd';  //设置系统的短日期格式为 年-月-日
    s:=formatdatetime('yyyymmdd', strtodate('2002-02-03'));
      

  6.   

    S := FormatDateTime('yyyymmdd', StrToDate('02-2-3'));
    Showmessage(S);