Min's blog

I choose to see the beauties in the world.

导航

实时时间设置

Posted on 2018-03-29 16:32  Min77  阅读(201)  评论(0编辑  收藏  举报

//时钟设置
function addZero(n) {
return n < 10 ? '0' + n : '' + n;
}


function tick() {
var today = new Date();
var yy = today.getYear();
if (yy < 1900) yy = yy + 1900;
var MM = today.getMonth() + 1;
var dd = today.getDate();
var hh = today.getHours();
var mm = today.getMinutes();
var ss = today.getSeconds();
var ww = today.getDay();
var arr = ['日', '一', '二', '三', '四', '五', '六'];
document.getElementById("localtime").innerHTML = "<p class='t1'>" + addZero(hh) + ":" + addZero(mm) + ":" + addZero(ss) + "</p>" + " " + "<p class='t2'>" + addZero(MM) + "月" + addZero(dd) + "日" + "<span>" + "星期" + arr[ww] + "</span>" + "</p>";
}
tick();
setInterval(tick, 1000);