JS显示当前时间

<div id="clock"></div>
window.setInterval('showRealTime(clock)', 1000);
function showRealTime(clock) {
    var d = new Date();
    var year = d.getFullYear();
    var month = d.getMonth() + 1;
    var date = d.getDate();
    var days = new Array("", "", "", "", "", "", "");
    var day = d.getDay();
    var hour = (d.getHours() < 10) ? ("0" + d.getHours()) : d.getHours();
    var min = (d.getMinutes() < 10) ? ("0" + d.getMinutes()) : d.getMinutes();
    var sec = (d.getSeconds() < 10) ? ("0" + d.getSeconds()) : d.getSeconds();
    var now = year + "" + month + "" + date + "日&nbsp;&nbsp;星期" + days[day] + "&nbsp;&nbsp;" + hour + ":" + min + ":" + sec;
    clock.innerHTML = now;
}

 

posted @ 2019-07-23 18:08  时光博客  阅读(187)  评论(0编辑  收藏  举报