JavaScript将日期转换成中文格式的函数
2009-07-12 20:13:46 来源:WEB开发网核心提示:function CNDateString(date){ var cn = ["〇","一","二","三","四","五","六","七","八&
function CNDateString(date)
{
var cn = ["〇","一","二","三","四","五","六","七","八","九"];
var s = [];
var YY = date.getFullYear().toString();
for (var i=0; i<YY.length; i++)
if (cn[YY.charAt(i)])
s.push(cn[YY.charAt(i)]);
else
s.push(YY.charAt(i));
s.push("年");
var MM = date.getMonth();
if (MM<10)
s.push(cn[MM]);
else if (MM<20)
s.push("十" + cn[MM% 10]);
s.push("月");
var DD = date.getDate();
if (DD<10)
s.push(cn[DD]);
else if (DD<20)
s.push("十" + cn[DD% 10]);
else
s.push("二十" + cn[DD% 10]);
s.push("日");
return s.join('');
}
Example:
程序代码
alert(CNDateString(new Date()));
Tags:JavaScript 日期 转换
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接