JS显示当前时间

<div id="clock"></div>
<script>
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 + "日  星期" + days[day] + "  " + hour + ":" + min + ":" + sec;
    clock.innerHTML = now;
}
</script>

演示

© 版权声明
THE END
喜欢就支持一下吧
点赞8赞赏 分享
评论 抢沙发

请登录后发表评论