function cnFormatDate(Date:TDate):String; var tempDate:String; i:Integer; const chrTen='T'; chrYear='J'; chrMonth='K'; chrDay='L'; begin tempDate:=FormatDatetime('yyyy'+chrYear+'MM'+chrMonth+'dd'+chrDay,Date);//日期转换 if tempDate[9]='1' then tempDate[9]:=chrTen; if tempDate[9] in ['2','3'] then begin setlength(tempDate,12); tempDate[12]:=tempDate[11]; tempDate[11]:=tempDate[10]; tempDate[10]:=chrTen; end;//月份转换 if tempDate[6]='1' then tempDate[6]:=chrTen else begin for i:=6 to length(tempDate)-1 do tempDate[i]:=tempDate[i+1]; setlength(tempDate,length(tempDate)-1); end;tempDate:=stringreplace(tempDate,'0','零',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'1','一',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'2','二',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'3','三',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'4','四',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'5','五',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'6','六',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'7','七',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'8','八',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'9','九',[rfReplaceAll]); tempDate:=stringreplace(tempDate,chrTen,'十',[rfReplaceAll]); tempDate:=stringreplace(tempDate,chrYear,'年',[rfReplaceAll]); tempDate:=stringreplace(tempDate,chrMonth,'月',[rfReplaceAll]); tempDate:=stringreplace(tempDate,chrDay,'日',[rfReplaceAll]); RESULT:=tempDate; end;
这是我自己写的函数 我写的第一个。。就是它function EDatetoChinaDate(Edate:TDatetime):string; var i:integer; tmp1:string; sTmp1:String; GzfTmp:string; GZFint:integer; begin tmp1:=formatdatetime('yyyy-mm-dd',Edate); if length(tmp1)<8 then MsgDlgEx('字符格式有误!',mtInformation,[mbOk],0); FOR I:=1 TO 4 DO begin GzfTmp:=COPY(tmp1,I,1); GZFint:=strtoint(GzfTmp); case GZFint of 1: sTmp1:='一';// 2: sTmp1:='二';// 3: sTmp1:='三';// 4: sTmp1:='四';// 5: sTmp1:='五';// 6: sTmp1:='六';// 7: sTmp1:='七';// 8: sTmp1:='八';// 9: sTmp1:='九';// 0: sTmp1:='0';// end; result:=result+sTmp1; end; result:=result+'年'; GzfTmp:=COPY(tmp1,6,1); GZFint:=strtoint(GzfTmp); case GZFint of 1: sTmp1:='十';// 0: sTmp1:='';// else sTmp1:=''; end; result:=result+sTmp1; GzfTmp:=COPY(tmp1,7,1); GZFint:=strtoint(GzfTmp); case GZFint of 1: sTmp1:='一';// 2: sTmp1:='二';// 3: sTmp1:='三';// 4: sTmp1:='四';// 5: sTmp1:='五';// 6: sTmp1:='六';// 7: sTmp1:='七';// 8: sTmp1:='八';// 9: sTmp1:='九';// 0: sTmp1:='';// else MsgDlgEx('字符格式有误!',mtInformation,[mbOk],0); end; result:=result+sTmp1+'月'; GzfTmp:=COPY(tmp1,9,1); GZFint:=strtoint(GzfTmp); case GZFint of 1: sTmp1:='十';// 2: sTmp1:='二十';// 3: sTmp1:='三十';// 0: sTmp1:='';// else MsgDlgEx('字符格式有误!',mtInformation,[mbOk],0); end; result:=result+sTmp1; GzfTmp:=COPY(tmp1,10,1); GZFint:=strtoint(GzfTmp); case GZFint of 1: sTmp1:='一';// 2: sTmp1:='二';// 3: sTmp1:='三';// 4: sTmp1:='四';// 5: sTmp1:='五';// 6: sTmp1:='六';// 7: sTmp1:='七';// 8: sTmp1:='八';// 9: sTmp1:='九';// 0: sTmp1:='';// else MsgDlgEx('字符格式有误!',mtInformation,[mbOk],0); end; result:=result+sTmp1+'日';end;现在看来比较菜呵呵,不过还可以用。。你试试
function cnFormatDate(Date:TDate):String; var tempDate:String; i:Integer; const chrTen='T'; chrYear='J'; chrMonth='K'; chrDay='L'; begin tempDate:=FormatDatetime('yyyy'+chrYear+'MM'+chrMonth+'dd'+chrDay,Date); //日期转换 if tempDate[10]='0' then Delete(tempDate,10,1); if tempDate[9] in ['2','3'] then insert(chrTen,tempDate,10); if tempDate[9]='1' then tempDate[9]:=chrTen; if tempDate[9]='0' then Delete(tempDate,9,1); //月份转换 if tempDate[7]='0' then Delete(tempDate,7,1); if tempDate[6]='1' then tempDate[6]:=chrTen else delete(tempDate,6,1); tempDate:=stringreplace(tempDate,'0','零',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'1','一',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'2','二',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'3','三',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'4','四',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'5','五',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'6','六',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'7','七',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'8','八',[rfReplaceAll]); tempDate:=stringreplace(tempDate,'9','九',[rfReplaceAll]); tempDate:=stringreplace(tempDate,chrTen,'十',[rfReplaceAll]); tempDate:=stringreplace(tempDate,chrYear,'年',[rfReplaceAll]); tempDate:=stringreplace(tempDate,chrMonth,'月',[rfReplaceAll]); tempDate:=stringreplace(tempDate,chrDay,'日',[rfReplaceAll]); RESULT:=tempDate;end; 刚才写的,十位后面的零忘去了,重写如上
然后将阿拉伯数字转为中文数字。例如:formatDate('yyyy年mm月dd日 dddd hh:mm:ss',NOW)得到的是:2005年04月11日 星期一 16:48:58然后你可以使用EnumToCnum函数将阿拉伯数字转为中文数字。
EnumToCnum函数是自己写的,你也可以到www.2ccc.com去查找。
var
tempDate:String;
i:Integer;
const
chrTen='T';
chrYear='J';
chrMonth='K';
chrDay='L';
begin
tempDate:=FormatDatetime('yyyy'+chrYear+'MM'+chrMonth+'dd'+chrDay,Date);//日期转换
if tempDate[9]='1' then tempDate[9]:=chrTen;
if tempDate[9] in ['2','3'] then
begin
setlength(tempDate,12);
tempDate[12]:=tempDate[11];
tempDate[11]:=tempDate[10];
tempDate[10]:=chrTen;
end;//月份转换
if tempDate[6]='1' then tempDate[6]:=chrTen
else begin
for i:=6 to length(tempDate)-1 do tempDate[i]:=tempDate[i+1];
setlength(tempDate,length(tempDate)-1);
end;tempDate:=stringreplace(tempDate,'0','零',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'1','一',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'2','二',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'3','三',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'4','四',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'5','五',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'6','六',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'7','七',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'8','八',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'9','九',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,chrTen,'十',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,chrYear,'年',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,chrMonth,'月',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,chrDay,'日',[rfReplaceAll]);
RESULT:=tempDate;
end;
var
i:integer;
tmp1:string;
sTmp1:String;
GzfTmp:string;
GZFint:integer;
begin
tmp1:=formatdatetime('yyyy-mm-dd',Edate);
if length(tmp1)<8 then
MsgDlgEx('字符格式有误!',mtInformation,[mbOk],0);
FOR I:=1 TO 4 DO
begin
GzfTmp:=COPY(tmp1,I,1);
GZFint:=strtoint(GzfTmp);
case GZFint of
1: sTmp1:='一';//
2: sTmp1:='二';//
3: sTmp1:='三';//
4: sTmp1:='四';//
5: sTmp1:='五';//
6: sTmp1:='六';//
7: sTmp1:='七';//
8: sTmp1:='八';//
9: sTmp1:='九';//
0: sTmp1:='0';//
end;
result:=result+sTmp1;
end;
result:=result+'年';
GzfTmp:=COPY(tmp1,6,1);
GZFint:=strtoint(GzfTmp);
case GZFint of
1: sTmp1:='十';//
0: sTmp1:='';//
else
sTmp1:='';
end;
result:=result+sTmp1;
GzfTmp:=COPY(tmp1,7,1);
GZFint:=strtoint(GzfTmp);
case GZFint of
1: sTmp1:='一';//
2: sTmp1:='二';//
3: sTmp1:='三';//
4: sTmp1:='四';//
5: sTmp1:='五';//
6: sTmp1:='六';//
7: sTmp1:='七';//
8: sTmp1:='八';//
9: sTmp1:='九';//
0: sTmp1:='';//
else
MsgDlgEx('字符格式有误!',mtInformation,[mbOk],0);
end;
result:=result+sTmp1+'月';
GzfTmp:=COPY(tmp1,9,1);
GZFint:=strtoint(GzfTmp);
case GZFint of
1: sTmp1:='十';//
2: sTmp1:='二十';//
3: sTmp1:='三十';//
0: sTmp1:='';//
else
MsgDlgEx('字符格式有误!',mtInformation,[mbOk],0);
end;
result:=result+sTmp1;
GzfTmp:=COPY(tmp1,10,1);
GZFint:=strtoint(GzfTmp);
case GZFint of
1: sTmp1:='一';//
2: sTmp1:='二';//
3: sTmp1:='三';//
4: sTmp1:='四';//
5: sTmp1:='五';//
6: sTmp1:='六';//
7: sTmp1:='七';//
8: sTmp1:='八';//
9: sTmp1:='九';//
0: sTmp1:='';//
else
MsgDlgEx('字符格式有误!',mtInformation,[mbOk],0);
end;
result:=result+sTmp1+'日';end;现在看来比较菜呵呵,不过还可以用。。你试试
var
tempDate:String;
i:Integer;
const
chrTen='T';
chrYear='J';
chrMonth='K';
chrDay='L';
begin tempDate:=FormatDatetime('yyyy'+chrYear+'MM'+chrMonth+'dd'+chrDay,Date); //日期转换
if tempDate[10]='0' then Delete(tempDate,10,1); if tempDate[9] in ['2','3'] then insert(chrTen,tempDate,10);
if tempDate[9]='1' then tempDate[9]:=chrTen;
if tempDate[9]='0' then Delete(tempDate,9,1); //月份转换
if tempDate[7]='0' then Delete(tempDate,7,1);
if tempDate[6]='1' then tempDate[6]:=chrTen else delete(tempDate,6,1); tempDate:=stringreplace(tempDate,'0','零',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'1','一',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'2','二',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'3','三',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'4','四',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'5','五',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'6','六',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'7','七',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'8','八',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,'9','九',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,chrTen,'十',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,chrYear,'年',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,chrMonth,'月',[rfReplaceAll]);
tempDate:=stringreplace(tempDate,chrDay,'日',[rfReplaceAll]); RESULT:=tempDate;end;
刚才写的,十位后面的零忘去了,重写如上