var
ts :String;
chn :String;
i :Byte;
begin
ts := FormatDateTime('yyyy"年"mm"月"dd"日"', Strtodate('2002-07-09'));
chn := '';
for i:= 1 to Length(ts) do
begin
case ts[i] of
0:
chn := chn+'零';
1:
chn := chn+'壹';
...
9:
chn := chn+'玖';
else
chn := chn+ts[i];
end;
//chn即为中文日期
end;
ts :String;
chn :String;
i :Byte;
begin
ts := FormatDateTime('yyyy"年"mm"月"dd"日"', Strtodate('2002-07-09'));
chn := '';
for i:= 1 to Length(ts) do
begin
case ts[i] of
0:
chn := chn+'零';
1:
chn := chn+'壹';
...
9:
chn := chn+'玖';
else
chn := chn+ts[i];
end;
//chn即为中文日期
end;
function DateCn(mDate: TDate): string;
const
cNumberCn: WideString = '零壹贰叁肆伍陆柒捌玖';
var
I: Integer;
begin
Result := FormatDateTime('YYYY"年"M"月"D"日"', mDate);
for I := 0 to 9 do
Result := StringReplace(Result, IntToStr(I), cNumberCn[I + 1], [rfReplaceAll]);
end; { DateCn }
///////End Source///////Begin Demo
procedure TForm1.Button1Click(Sender: TObject);
begin
Caption := DateCn(Date);
end;
///////End Demo
const
cHZ: array[0..9]of string = ('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
begin
Result := cHZ[Value];
end;function DateToChinese(const Value: Date): String;
var
vDate: String;
I: Integer;
begin
vDate := FormatDateTime('yyyymmdd', Value);
Result := '';
for I := 1 to Length(vDate) do
begin
Result := Result + DigitToHZ(StrToInt(vDate[I]));
case Length(Result) of //可优化,我偷懒:-)
8: Result := Result + '年';
14: Result := Result + '月';
20: Result := Result + '日';
end;
end;
end;//上述代码未经调试,经出炉的,有兴趣的朋友可以加以完善!!
//CoolSlob.即日.即时.
我比较菜,以上大于10号的日期表示不正确,该如何改进?
var
ts :String;
chn :String;
i :Byte;
begin
ts := FormatDateTime('yyyy"年"mm"月"dd"日"', dxDateEdit1.Date);
chn := '';
for i:= 1 to Length(ts) do
begin
try
case strtoint(ts[i]) of
0:
chn := chn+'零';
1:
chn := chn+'壹';
2:
chn := chn+'贰';
3:
chn := chn+'叁';
4:
chn := chn+'肆';
5:
chn := chn+'伍';
6:
chn := chn+'陆';
7:
chn := chn+'柒';
8:
chn := chn+'捌';
9:
chn := chn+'玖';
end;
except
chn := chn+ts[i];
end; end;
//chn即为中文日期
dxedit1.Text := chn;
end;