<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>动态显示时间</title>
</head>
<body>
<div style="width: 500px;height: 500px;border: 1px solid blue;" id="time"></div>
</body>
<script type="text/javascript">
function getD(){
//获取到当前时间
var date=new Date();
//将日期格式化
var d1=date.toLocaleString();
//获取div
var div1=document.getElementById("time");
div1.innerHTML=d1;
}
//使用定时器实现每一秒写一次
setInterval("getD()",1000);
</script>
</html>
<html>
<head>
<meta charset="UTF-8">
<title>动态显示时间</title>
</head>
<body>
<div style="width: 500px;height: 500px;border: 1px solid blue;" id="time"></div>
</body>
<script type="text/javascript">
function getD(){
//获取到当前时间
var date=new Date();
//将日期格式化
var d1=date.toLocaleString();
//获取div
var div1=document.getElementById("time");
div1.innerHTML=d1;
}
//使用定时器实现每一秒写一次
setInterval("getD()",1000);
</script>
</html>