不多说 上源码:
1 function formatDate(dateString) { 2 dateString = dateString.replace("/", "").replace("/", "").replace("Date", "").replace("(", "").replace(")", "").replace("-", ""); 3 var date = new Date(parseFloat(dateString)); 4 var year = date.getFullYear(); 5 var m = date.getMonth() + 1; 6 var d = date.getDate(); 7 var reM = "" + m; 8 if (reM.length == 1) { 9 reM = "0" + m; 10 } 11 var reD = "" + d; 12 if (reD.length == 1) { 13 reD = "0" + d; 14 } 15 16 var h = "" + date.getHours(); 17 h = (h.length == 1) ? ("0" + h) : h; 18 var M = "" + date.getMinutes(); 19 M = (M.length == 1) ? ("0" + M) : M; 20 var s = "" + date.getSeconds(); 21 s = (s.length == 1) ? ("0" + s) : s; 22 return year + "-" + reM + "-" + reD + " " + h + ":" + M + ":" + s; 23 }
转换后格式为:
yyyy-mm-dd hh:MM:ss
注意:日期和时间之间存在空格。