<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="js/tools.js"></script>
</head>
<body>
<div></div>
<script>
var div = document.querySelector('div');
setInterval (function(){var res = timer();
div.innerHTML = '当前时间:'+res; // y +'-'+ add0(m) +'-'+ add0(d) +' '+add0(h)+':'+add0(mi)+':'+ add0(s) ;
},1000)
</script>
</body>
</html>
//显示系统实时时间:(在html中加入一个定时器调用这个函数)functiontimer(){var y = new Date().getFullYear();
var m = new Date().getMonth() + 1;
var d = new Date().getDate();
var h = new Date().getHours();
var mi = new Date().getMinutes();
var s = new Date().getSeconds();
return y +'-'+ add0(m) +'-'+ add0(d) +' '+add0(h)+':'+add0(mi)+':'+ add0(s);
}
functionadd0(num){//用于判断月日小时分钟秒为个位数时变成09if(num>9){
return num;
}else{
return'0'+num;
}
}