构造函数
Date.prototype.toHyphenDateString = function() {
var year = this.getFullYear();
var month = this.getMonth() + 1;
var date = this.getDate();
var hours=this.getHours();
var minutes=this.getMinutes();
var seconds=this.getSeconds();
if (month < 10) { month = "0" + month; }
if (date < 10) { date = "0" + date; }
if(hours < 10) { hours= "0" + hours}
if(minutes < 10) { minutes= "0" + minutes}
if(seconds < 10) { seconds= "0" + seconds}
return year + "-" + month + "-" + date + " "+hours+":"+minutes+":"+seconds;
};
timeShow();
setInterval(timeShow,1000);
function timeShow(){
var date=new Date();
var str=date.toHyphenDateString();
$('.time').text("当前时间:"+str);//jQuery方法,将时间显示在类为time的标签内
}