javascript簡單實(shí)現(xiàn)時(shí)鐘的例子,具體實(shí)現(xiàn)
代碼如下:
<body onload=updatenowtime()>
<p id=nt></p>
<script>
/*一段時(shí)鐘小例子 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)前時(shí)間是: + year + - + month + - + day + + caltime(hours) + : + caltime(minutes) + : + caltime(secs);
}
setinterval('updatenowtime()', 500);
</script>
</body>