本文整理自网络,侵删。
获取当前日期,日期为数字。将数字转换成中文。
function TForm1.GetCNDay():string; //result是function默认的返回值变量var str,strYear,strMonth,strDay,e,n,s : string; year,month,day,v_index,v_len,i : Integer;begin e:='0123456789'; n:='?一二三四五六七八九'; v_index:=1; Result:=''; strYear:=formatDateTime('yyyy',Now()); strMonth:= formatDateTime('mm',Now()); strDay:= formatDateTime('dd',Now()); year:=StrToInt(strYear); month:=StrToInt(strMonth); day:=StrToInt(strDay); if month<10 then strMonth:=IntToStr(month) else if month =10 then strMonth:='十' else if month>10 then strMonth:='十' + IntToStr(month-10); strMonth:=strMonth+'月'; if day <10 then strDay:=inttostr(day) else if(day = 10) then strDay:='十' else if(day>10) and (day<20)then strDay:='十'+ inttostr(day-10) else if(day = 20)then strDay:='二十' else if(day>20) and (day < 30)then strDay:='二十'+ inttostr(day-20) else if(day =30)then strDay:='三十' else if(day=31)then strDay:='三十一'; str:= strYear +'年'+ strMonth + strDay+'日'; v_len:=Length(str); for i:=1 to v_len do begin s:=MidStr(str,i,1); if Pos(s,e)>0 then Result:=Result+MidStr(n,Pos(s,e),1) else Result:=Result+s; end; end;
相关阅读 >>
Delphi xe7里面 sharedactivitycontext怎么提示错误?
Delphi利用微软sapi实现语音控制(Delphi,tts,sr,灰色代码)_
更多相关阅读请进入《Delphi》频道 >>