JS简单实现时间走动

827 阅读1分钟
[广州PHP]JS简单实现时间走动。

后台网站,一般会有一个当前时间,该时间和当前的时间一致,并且会不停的走动。现在简单实现个会走的时间。
[HTML]
纯文本查看
复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script type="text/javascript">
function startTime()
{
var today=new Date();
var y = today.getFullYear();
var month = today.getMonth() + 1;
var d = today.getDate();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
//不足10的情况,前面加0
month=checkTime(month);
d=checkTime(d);
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=y+"-"+month+"-"+d+" "+h+":"+m+":"+s
t=setTimeout('startTime()',500)
}
function checkTime(i)
{
if (i<10)
{i="0" + i}
return i
}
</script>
</head>
<body>
<div id="txt"></div>
</body>
</html>




效果如下



更多技术资讯可关注:gzitcast