我用的简单的直接的字符串格式转化
function getTimeStr() { var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); var hours = date.getHours(); var minutes = date.getMinutes(); if (month.length == 1) { month = "0" + month; } if (day.length == 1) { day = "0" + day; } if (hours.length == 1) { hours = "0" + hours; } if (minutes.length == 1) { minutes = "0" + minutes; } var d = year + "-" + month + "-" + day + " " + hours + ":" + minutes; return d; }