富贵资源网 Design By www.hznty.com

1.第一种方法

<table>
<tr>
<td>当前时间:</td>
<td id="CurrentTime"></td>
<script type="text/javascript">
function changetime(){
var ary = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
var Timehtml = document.getElementById('CurrentTime');
var date = new Date();
Timehtml.innerHTML = ''+date.toLocaleString()+' '+ary[date.getDay()];
}
</script> 
</tr>
</table>

2.第二种方法

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="gb2312">
<title></title>
<script type="text/javascript"> 
window.onload=function(){ 
setInterval(function(){ 
var date=new Date(); 
var year=date.getFullYear(); //获取当前年份 
var mon=date.getMonth()+1; //获取当前月份 
var da=date.getDate(); //获取当前日 
var day=date.getDay(); //获取当前星期几 
var h=date.getHours(); //获取小时 
var m=date.getMinutes(); //获取分钟 
var s=date.getSeconds(); //获取秒 
var d=document.getElementById('Date'); 
d.innerHTML='当前时间:'+year+'年'+mon+'月'+da+'日'+'星期'+day+' '+h+':'+m+':'+s; },1000) }
</script>
</head>
<body>
<div id="Date"> </div>
</body>
</html>

3.第一种方法

<!DOCTYPE html> 
<html> 
<body> 
<div id="show"></div>

<script type="text/javascript"> 
window.onload = function() { 
var show = document.getElementById("show"); 
setInterval(function() { 
var time = new Date(); // 程序计时的月从0开始取值后+1 
var m = time.getMonth() + 1; 
var t = time.getFullYear() + "-" + m + "-"

time.getDate() + " " + time.getHours() + ":"
time.getMinutes() + ":" + time.getSeconds(); 
show.innerHTML = t; 
}, 1000); 
};
</script>
</body> 
</html>

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com