delphi 时间转成大写


本文整理自网络,侵删。

 
很多时候,中国的日历生辰八字都会用不用 汉字的大写来写,这个函数专门为那些想要让时间大写的人提供使用,让时间变得更有意义。


function DateToCapital(datetime: TDateTime): string;
const Capital: array[0..9] of string = ('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
  mCapital: array[0..5] of string = ('零', '拾', '贰拾', '叁拾', '肆拾', '伍拾');
var tmp: string;
  function DivideByZero(s: string): string;
  var x: integer;
  begin
    Result := '';
    try
      x := strtoint(s);
      if x > 9 then
      begin
        if s[1] <> '0' then
          Result := mCapital[strtoint(s[1])];
        if s[2] <> '0' then
          Result := Result + Capital[strtoint(s[2])];
      end
      else
      begin
        Result := Result + Capital[strtoint(s[2])];
      end;
    except
    end;
  end;
begin
  Result := '';
  if datetime = null then exit;
  tmp := formatdatetime('yyyymmddhhnnss', datetime);
  Result := Capital[strtoint(tmp[1])]
    + Capital[strtoint(tmp[2])]
    + Capital[strtoint(tmp[3])]
    + Capital[strtoint(tmp[4])]
    + '年';
  Result := Result + DivideByZero(tmp[5] + tmp[6]);
  Result := Result + '月';
  Result := Result + DivideByZero(tmp[7] + tmp[8]);
  Result := Result + '日';
  Result := Result + DivideByZero(tmp[9] + tmp[10]);
  Result := Result + '时';
  Result := Result + DivideByZero(tmp[11] + tmp[12]);
  Result := Result + '分';
  Result := Result + DivideByZero(tmp[13] + tmp[14]) + '秒';
end;
//调用方法
procedure TForm1.Button1Click(Sender: TObject);
begin
  showmessage(DateToCapital(now));
end;

来源:http://www.delphifmx.com/node/66

相关阅读 >>

Delphi 通得进程id获取主窗口句柄

Delphi调试技巧

Delphi 10.3 断点调试相关快捷键

Delphi 执行程序并等待完成2

Delphi 安卓开发 ioutils文件说明

Delphi 如何把一个exe做为res加入到dll中,并在运行时生成exe文件执行

Delphi中inputbox 和inputquery 函数的使用

Delphi 纯window系统api实现的ssl客户端

Delphi fmx 获取控件句柄

Delphi 文件路径获取文件名不带扩展名

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...