javascript-实现日期大写
<script language="javascript"> $(document).ready(function() { //定义中文数组 var chinese = ['〇', '一', '二', '三', '四', '五', '六', '七', '八', '九']; //分别获取年月日 var y = endTime.substr(0, 4); var m = endTime.substr(5, 2); var d = endTime.substr(8, endTime.length - 8); //定义返回结果集 var result = ""; //循环年份 for (var i = 0; i < y.length; i++) { result += chinese[y.charAt(i)]; } //拼接到返回结果集中 result += "年"; //如果月份为两位数,则返回十的月份拼接一次数据,其它则返回寻常的值 if (m.length == 2) { if (m.charAt(0) == "0") { result += (chinese[m.charAt(1)] + "月"); } if (m.charAt(0) == "1") { result += ("十" + chinese[m.charAt(1)] + "月"); } } else { result += (chinese[m.charAt(0)] + "月"); } //如果日为两位数,则返回十的月份拼接两次数据,其它则返回寻常的值 if (d.length == 2) { result += (chinese[d.charAt(0)] + "十" + chinese[d.charAt(1)] + "日"); } else { result += (chinese[d.charAt(0)] + "日"); } return result; }); </script>