var replaceStar = function (index) { var a switch (index) { case '1': a = '出生时' break; case '2': a = '1月龄' break; case '3': a = '2月龄' break; case '4': a = '3月龄' break; case '5': a = '4月龄' break; case '6': a = '5月龄' break; case '7': a = '6月龄' break; case '8': a = '8月龄' break; case '9': a = '9月龄' break; case '10': a = '1岁6月龄' break; case '11': a = '2岁' break; case '12': a = '3岁' break; case '13': a = '4岁' break; case '14': a = '6岁' break; } return a; } var formatNumber = function(n){ n = n.toString() return n[1] ? n : '0' + n } var regYear = getRegExp("(y+)", "i"); var dateFormat = function(timestamp,format){ console.log("时间戳",timestamp) if (!format) { format = "yyyy-MM-dd hh:mm:ss"; } /* 显示真实时间*/ timestamp = parseInt(timestamp*1000); var realDate = getDate(timestamp); function timeFormat(num) { return num < 10 ? '0' + num : num; } console.log("时间戳realDate",realDate) var date = [ ["M+", timeFormat(realDate.getMonth() + 1)], ["d+", timeFormat(realDate.getDate())], ["h+", timeFormat(realDate.getHours())], ["m+", timeFormat(realDate.getMinutes())], ["s+", timeFormat(realDate.getSeconds())], ["q+", Math.floor((realDate.getMonth() + 3) / 3)], ["S+", realDate.getMilliseconds()], ]; var reg1 = regYear.exec(format); // console.log(reg1[0]); if (reg1) { format = format.replace(reg1[1], (realDate.getFullYear() + '').substring(4 - reg1[1].length)); } for (var i=0;i