电子表
<!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>