动态时钟
Posted mrhunag
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了动态时钟相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>document的属性</title>
</head>
<body>
<input type="button" value="获取当前时间" onclick="getClock()">
<div id="showtime"></div>
<input type="button" id="mycolock" value="暂停" onclick="stopRun()">
</body>
</html>
<script type="text/javascript">
function getClock()
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDay();
var weekday = new Array(7);
weekday[0] = "星期一";
weekday[1] = "星期二";
weekday[2] = "星期三";
weekday[3] = "星期四";
weekday[4] = "星期五";
weekday[5] = "星期六";
weekday[6] = "星期天";
var hh = date.getHours();
var minute = date.getMinutes();
var ss = date.getSeconds();
var tm = "AM";
if (hh > 12)
var tm = "PM";
var nowTime = ("现在是北京时间:" + year + "年" + month + "月" + day + "日" + "   " + hh + ":" + minute + ":" + ss + "  " + weekday[date.getDay()] + "   " + tm)
document.getElementById("showtime").innerHTML = nowTime;
// setTimeout("getClock()", 1000);
var mytime = setInterval("getClock()", 1000);
function stopRun()
var stop9= document.getElementById("mycolock");
if (stop9.value == "暂停")
clearInterval(mytime);
stop9.value = "开始";
else
mytime = setInterval("getClock()", 1000);
stop9.value = "暂停";
</script>
以上是关于动态时钟的主要内容,如果未能解决你的问题,请参考以下文章