<script type="text/javascript"> function toCn(n){//把数字转换成相应的汉字 var n_cn = ""; switch(n){ case "0" : n_cn = "零"; break; case "1": n_cn = "一"; break; case "2" : n_cn = "二"; break; case "3": n_cn = "三"; break; case "4" : n_cn = "四"; break; case "5": n_cn = "五"; break; case "6" : n_cn = "六"; break; case "7": n_cn = "七"; break; case "8" : n_cn = "八"; break; case "9": n_cn = "九"; break; default: break; } return n_cn; } function change_ch(date){//固定格式日期转换为汉字,如果 2012-02-09 var tem = date.split("-"); var date_cn = ""; //年份 for(var i = 0; i < tem[0].length; i++){ date_cn = date_cn + toCn(tem[0].charAt(i)); } date_cn = date_cn + "年"; //月份 if(tem[1].charAt(0) == "1"){ date_cn = date_cn + "十" + toCn(tem[1].charAt(1)); } else { date_cn = date_cn + toCn(tem[1].charAt(1)); } date_cn = date_cn + "月"; //日 if(tem[2].charAt(0) == "0"){ date_cn = date_cn + toCn(tem[2].charAt(1)); } else if (tem[2].charAt(0) == "1"){ date_cn = date_cn + "十" + toCn(tem[2].charAt(1)); } else { date_cn = date_cn + toCn(tem[2].charAt(0)) + "十" + toCn(tem[2].charAt(1)); } date_cn = date_cn + "日"; alert(date_cn); } change_ch("2012-14-24"); </script>