首页 > 代码库 > 页面显示时间----最简

页面显示时间----最简

技术分享

 

<html lang="en">
<head>
<meta charset="UTF-8">
<script src="http://www.mamicode.com/jquery-3.1.0.js"></script>
<title></title>
<style>
div{
text-align: center;
margin-top: 100px;
font-size: 30px;
}
</style>
</head>
<body>

<div>20:20:20</div>

<script>
$(function () {
var div = document.querySelector(‘div‘)
function time1 () {
var now = new Date()
div.innerHTML = now.toTimeString().substring(0, 9)
}
time1()
setInterval(time1,1000)
})
</script>
</body>
</html>

 

页面显示时间----最简