Date类型以YYYY-MM-DD hh:mm:ss格式打印出来:
Date.prototype.formate=function(){
var year=this.getFullYear();
var month=(this.getMonth()+1<10)?("0"+(this.getMonth()+1)):this.getMonth()+1;
var date=(this.getDate()<10)?("0"+(this.getDate())):this.getDate();
var hours=(this.getHours()<10)?("0"+(this.getHours())):this.getHours();
var minute=(this.getMinutes()<10)?("0"+(this.getMinutes())):this.getMinutes();
var seconds=(this.getSeconds()<10)?("0"+(this.getSeconds())):this.getSeconds();
var time=year+"-"+month+"-"+date+" "+hours+":"+minute+":"+seconds;
return time;
}
使用时调用formate方法即可:
例如:
var date=new Date();
date.formate();
"2015-04-08 12:28:35"