delphi里的时间字段为2001-11-11,怎样显示为汉字,或者在报表打印为汉字?即打印为'二00一年十一月十一日'我用的报表是fastreport2.47

解决方案 »

  1.   

    是delphi 内的Tdate  变量,还是取数据库的datetime 字段?
      

  2.   

    可以用formatdatetime('dddddd',date),但是还要设置系统的长时间类型。
      

  3.   

    写个函数转function TForm1.DateToCnStr(dt:TDateTime):string;
    const
      numtochar:array[0..9] of string =('〇', '一', '二', '三', '四', '五', '六','七','八','九');
      numtomonth:array[0..9] of string =('十','一', '二', '三', '四', '五', '六','七','八','九');
    var
      fmts:string;//格式时间字符变量.
      nowy,nowm,nowd :string; //当前年月日变量.中文
      nowy1,nowy2,nowy3,nowy4,nowm1,nowm2,nowd1,nowd2:integer;//子变量.
    begin
      fmts:=formatdatetime('yyyy-mm-dd',dt);
      //转换当前年份
      nowy1:=strtoint(copy(fmts,1,1));
      nowy2:=strtoint(copy(fmts,2,1));
      nowy3:=strtoint(copy(fmts,3,1));
      nowy4:=strtoint(copy(fmts,4,1));
      nowy:=numtochar[nowy1]+numtochar[nowy2]+numtochar[nowy3]+numtochar[nowy4];
      //转换当前月份
      nowm1:=strtoint(copy(fmts,6,1));
      nowm2:=strtoint(copy(fmts,7,1));
      case nowm1 of
        0: nowm:=numtomonth[nowm2]; //eg:01
        1:
          if nowm2=0 then
            nowm:=numtomonth[0]    //eg:10
          else
            nowm:=numtomonth[0]+numtomonth[nowm2]; //eg:11
      end;
      //转换当前日期
      nowd1:=strtoint(copy(fmts,9,1));
      nowd2:=strtoint(copy(fmts,10,1));
      case nowd1 of
        0: nowd:=numtomonth[nowd2]; //eg:01
        1:
          if nowd2=0 then
            nowd:=numtomonth[0]     //eg:10
          else
            nowd:=numtomonth[0]+numtomonth[nowd2]; //eg:11
        else
        begin
          if nowd2=0 then
            nowd:=numtomonth[nowd1]+numtomonth[0]  //eg:20 or 30
          else
            nowd:=numtomonth[nowd1]+numtomonth[0]+numtomonth[nowd2]; //eg:21 or 31
        end;
      end;
      Result := nowy+'年'+nowm+'月'+nowd+'日';
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      edit1.Text :=  DateToCnStr(datetimepicker1.Date);
    end;
      

  4.   

    Function XX(sDate:TDateTime):string;
    Const
      Arr1:array[0..10] of string=('〇','一','二','三','四','五','六','七','八','九','十');
      Arr2:array[0..2] of string=('年','月','日');
    var
      s:string;
      i,j:Integer;
    begin
      s:=FormatDateTime('yyyymmdd',sDate);
      for i:=1 to 8 do
      begin
        j:=StrToInt(s[i]);    if not (i in [5,7]) then
        if not ((i in [6,8]) and (j=0)) then
           result:=result+Arr1[j];    case i of
        4,6,8:result:=result+Arr2[round((i-4)/2)];
        5,7:case j of
          1:result:=result+Arr1[10];
          2,3:result:=result+Arr1[j]+Arr1[10];
          end;
        end
      end;
    end;