格式化日期
Date()返回格式:
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 转换成标准时间
var parserDate = function (date) { var t = Date.parse(date); if (!isNaN(t)) { return new Date(Date.parse(date.replace(/-/g, "/"))); } else { return new Date(); } };