<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>數字时钟</title>
<style type="text/css">
#inner{
width: 300px;
height: 50px;
line-height: 50px;
text-align: center;
border: 1px solid #999;
float: right;
background: #FFC0CB;
}
</style>
</head>
<body>
<div id=inner>
</div>
<script type="text/javascript">
var o = document.getElementById("inner");
function getTime(){
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hour = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
month = addZero(month);
day = addZero(day);
hour = addZero(hour);
minutes = addZero(minutes);
seconds = addZero(seconds);
var time = year + "年" + month + "月" + day + "日" + " " + hour + ":" + minutes + ":" + seconds;
o.innerHTML = time;
}
function addZero(az) {
if(az < 10){
az = "0" + az;
}
return az;
}
getTime();
setInterval(getTime,1000);
</script>
</body>
</html>