*/
1.获取时间2015-07-28 10:11
*/
getTime: function(timeString, type) {
var date = new Date(timeString);
var year = date.getFullYear();
var month = date.getMonth() + 1;
month = month > 9 ? month : '0' + month;
var day = date.getDate() > 9 ? date.getDate() : '0' + date.getDate();
var hour = date.getHours() > 9 ? date.getHours() : '0' + date.getHours();
var minute = date.getMinutes() > 9 ? date.getMinutes() : '0' + date.getMinutes();
var second = date.getSeconds() > 9 ? date.getSeconds() : '0' + date.getSeconds();
if (!type) { //默认带上小时
return year + '-' + month + '-' + day + ' ' + hour;
} else if (type == 1) { //加上分钟
return year + '-' + month + '-' + day + ' ' + hour + ':' + minute;
} else if (type == 2) { //j加上秒
return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
} else if (type == 3) { //天
return year + '-' + month + '-' + day;
}
}
/*
2.获取时间戳
@parmas timeString = 2015-12-20 12:00 timeString不传则获取当前时间戳
*/
getTimeStamp: function(timeString) {
if (timeString) {
if (timeString.length == 13) {
timeString = timeString + ':00'; //不能只到小时
}
return Date.parse(new Date(timeString));
//or return new Date(timeString).getTime();
} else {
return Date.parse(new Date());
//or return new Date().getTime();
}
},