<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>获取当前最新时间</title>
</head>
<body>
</body>
<script type="text/javascript">
setInterval(function () {
var date=new Date();
var y=date.getFullYear();
var m=date.getMonth();
var d=date.getDate();
var h=date.getHours();
var min=date.getMinutes();
var s=date.getSeconds();
var msg="现在是"+y+"年"+(m+1)+"月"+d+"日 "+num(h)+":"+num(min)+":"+num(s);
document.body.innerHTML=msg;
},1000);
function num(n) {
if(n<10){
return "0"+n;
}else {
return n;
}
}
</script>
</html>