返回顶部

收藏

javascript实现时钟

更多
<body onload="updateNowTime()">
<p id="nt"></p>
<script>
    /*一段时钟小例子 write by yangxia 2013-05-23*/
    var calTime = function (t) {
        if (t < 10) t = "0" + t;
        return t;
    }

    var updateNowTime = function () {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1; //获取当前月0 - 11
        var day = date.getDate(); //获取当前日 1-31
        var hours = date.getHours();
        var minutes = date.getMinutes();
        var secs = date.getSeconds();

        document.getElementById("nt").innerHTML = "当前时间是:" + year + "-" + month + "-" + day + " " + calTime(hours) + ":" + calTime(minutes) + ":" + calTime(secs);
    }

    setInterval('updateNowTime()', 500);
</script>
</body>
//该片段来自于http://outofmemory.cn

标签:javascript,基础

收藏

0人收藏

支持

0

反对

0

发表评论