<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>定时器</title>
</head>
<body>
<p id="time"></p>
<script type="text/javascript">
function showTime(){
var myDate=new Date();
var hour=myDate.getHours();
var minutes=myDate.getMinutes();
var seconds=myDate.getSeconds();
if(hour<10)
hour="0"+hour;
if(minutes<10)
minutes="0"+minutes;
if(seconds<10)
seconds="0"+seconds;
document.getElementById("time").innerHTML="当前时间为:"+hour+":"+minutes+":"+seconds;
setTimeout("showTime()",1000);
}
window.onload=showTime;
</script>
</body>
</html>
使用setTimeout()定时器获取当前系统时间
最新推荐文章于 2024-06-20 12:02:41 发布