当前位置: 代码迷 >> JavaScript >> 用js兑现钟表
  详细解决方案

用js兑现钟表

热度:216   发布时间:2013-03-01 18:33:02.0
用js实现钟表
<html>
<meta charset='utf-8'/>
<head>
<script type="text/javascript">
function clock(){
var myDate=new Date();
var year=myDate.getYear();
var month=myDate.getMonth()+1;
var day=myDate.getDate();
var hour=myDate.getHours();
var mint=myDate.getMinutes();
var seconds=myDate.getSeconds();
var p=document.getElementById("p1");
p.innerHTML=year+"年"+month+"月"+day+"日"+hour+"时"+mint+"分"+seconds+"秒";
}
setInterval('clock()',500);
</script>
</head>
<body>
<div id='p1'></div>
</body>
</html>

  相关解决方案