js动态时间显示

本文共有757个字,关键词:

构造函数
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的标签内
}

注:更新的内容http://it.xiaomantu.com/web/jquery/176.html

版权声明:本文为作者原创,如需转载须联系作者本人同意,未经作者本人同意不得擅自转载。
添加新评论
暂无评论