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