电子表

<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>电子表</title>
<style type="text/css">
div {
width: 120px;
height: 40px;
font: normal 22px/40px 'STSong';
text-align: center;
color: brown;
border: 3px solid black;
border-radius: 5px;
margin: 50px auto;
}
</style>
</head>
<body>
<div>13:25:30</div>
</body>
<script type="text/javascript">
var div = document.querySelector('div');

function getNeedDate() {
var date = new Date();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();
return [hour, minute, second];
}

var n_date = getNeedDate();
div.innerText = n_date[0] + ":" + n_date[1] + ":" + n_date[2];

setInterval(function() {
n_date = getNeedDate();
// n_date[0] = n_date[0] < 10 ? '0' + n_date[0] : n_date[0];
for (var i = 0; i < n_date.length; i++) {
n_date[i] = n_date[i] < 10 ? '0' + n_date[i] : n_date[i];
}
div.innerText = n_date[0] + ":" + n_date[1] + ":" + n_date[2];
}, 300);
</script>
</html>

posted @ 2018-10-17 17:44  不沉之月  阅读(78)  评论(0编辑  收藏  举报