javascript簡單實(shí)現(xiàn)時鐘的例子,具體實(shí)現(xiàn)代碼如下:
<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; //獲取當(dāng)前月0 - 11
var day = date.getDate(); //獲取當(dāng)前日 1-31
var hours = date.getHours();
var minutes = date.getMinutes();
var secs = date.getSeconds();
document.getElementById("nt").innerHTML = "當(dāng)前時間是:" + year + "-" + month + "-" + day + " " + calTime(hours) + ":" + calTime(minutes) + ":" + calTime(secs);
}
setInterval('updateNowTime()', 500);
</script>
</body>
更多信息請查看IT技術(shù)專欄