方法一、
var dateStr = "/Date(1442760589000)/"; function GetStringDate(dateStr) { var date = eval('new ' + dateStr.substr(1, dateStr.length - 2)); var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); var hh = date.getHours(); var mm = date.getMinutes(); var ss = date.getSeconds(); return year + "-" + month + "-" + day + " " + hh + ":" + mm + ":" + ss; }
最终显示效果:2015-9-20 22:49:49
方法二、
var dateStr = "/Date(1442760589000)/"; function GetStringDate(dateStr) { var d = eval('new ' + dateStr.substr(1, dateStr.length - 2)); var ar_date = [d.getFullYear(), d.getMonth() + 1, d.getDate()]; for (var i = 0; i < ar_date.length; i++) { ar_date[i] = dFormat(ar_date[i]); } return ar_date.join('-'); function dateFormat(i) { return i < 10 ? "0" + i.toString() : i; } }
最终显示效果:2015-09-20
总结:2种方法思路一样,显示均可扩展。Mark备用。