码迷,mamicode.com
首页 > 其他好文 > 详细

动态时钟

时间:2019-09-10 17:43:01      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:date   mil   div   timeout   ntb   现在   body   type   tin   

<!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 + "日" + "&nbsp&nbsp&nbsp" + hh + ":" + minute + ":" + ss + "&nbsp&nbsp" + weekday[date.getDay()] + "&nbsp&nbsp&nbsp" + 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>

动态时钟

标签:date   mil   div   timeout   ntb   现在   body   type   tin   

原文地址:https://www.cnblogs.com/Mrhunag/p/11498413.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!