实现在jsp页面中显示一个动态时钟,每隔500毫秒刷新一次,刷新时间也可以自己设置,不废话,直接上代码吧!
<srcipt>
function startTime() {
var today = new Date();
var y = today.getFullYear();
var m = today.getMonth() + 1;
var d = today.getDay();
var h = today.getHours()
var mn = today.getMinutes()
var s = today.getSeconds()
// add a zero in front of numbers<10
m = checkTime(m)
s = checkTime(s)
document.getElementById('time').innerHTML = y + "-" + m + "-" + d + " "
+ h + ":" + mn + ":" + s
t = setTimeout('startTime()', 500)
}
function checkTime(i) {
if (i < 10) {
i = "0" + i
}
return i
}
</script>
<body οnlοad="startTime()">
<div id="time">
</body>