Date.prototype.toLocaleString=function(){
var year=this.getFullYear();
if((this.getMonth()+1)<10){
var month="0"+(this.getMonth() + 1);
}
if((this.getDate()<10)){
var day="0"+this.getDate();
}
// return this.getFullYear() + "-" + (this.getMonth() + 1) + "-" + this.getDate();
return year+'-'+month+'-'+day;
}
有些时间格式要求这样,可以在里面判断自己修改,这样定义就是:2010-01-01
Date.prototype.toLocaleString = function() { return this.getFullYear() + "年" + (this.getMonth() + 1) + "月" + this.getDate() + "日 " + this.getHours() + "点" + this.getMinutes() + "分" + this.getSeconds() + "秒"; };
2010年01月01日 12点12分12秒
new Date.getTime()
把时间转换成毫秒数
var newDate=new Date().getTime();
console.log(newDate);//把当前时间转换成毫秒
var oldTime = (new Date("2012/12/25 20:11:11")).getTime(); //得到毫秒数
console.log(oldTime);
var oldTime = (new Date("2012/12/25 20:11:11")).getTime(); //得到毫秒数
var newTime = new Date(oldTime); //就得到普通的时间了
console.log(newTime.toLocaleString());//转换成中文