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>
更多信息请查看IT技术专栏