格式化日期spa
Date()返回格式:code
Thu Mar 19 2015 12:00:00 GMT+0800 (中國標準時間)
轉成2015-05-19
var formatDate = function (date) { var y = date.getFullYear(); var m = date.getMonth() + 1; m = m < 10 ? '0' + m : m; var d = date.getDate(); d = d < 10 ? ('0' + d) : d; return y + '-' + m + '-' + d; };
var formatDateTime = function (date) { var y = date.getFullYear(); var m = date.getMonth() + 1; m = m < 10 ? ('0' + m) : m; var d = date.getDate(); d = d < 10 ? ('0' + d) : d; var h = date.getHours(); var minute = date.getMinutes(); minute = minute < 10 ? ('0' + minute) : minute; return y + '-' + m + '-' + d+' '+h+':'+minute; };
把2015-03-12 12:00 轉換成標準時間orm
var parserDate = function (date) { var t = Date.parse(date); if (!isNaN(t)) { return new Date(Date.parse(date.replace(/-/g, "/"))); } else { return new Date(); } };