delphi 数字转换成中文

本文介绍了一种使用Delphi编程语言将当前日期从数字格式转换为中文格式的方法。通过解析日期的不同部分(年、月、日),并将其转换为中文表示形式。此过程涉及条件判断与字符串操作。

获取当前日期,日期为数字。将数字转换成中文。

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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值