日期:2014-05-16  浏览次数:20390 次

js数字时钟


js数字时钟,效果如下:




<html>
	<head>
		 <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
	</head>

	<body>
		<span id="datetime" style="color: red"></span>
	</body>

 
 <script type="text/javascript">
	setTime();
  function setTime(){
      var mydate=new Date();
      var year = mydate.getFullYear();
      var mymonth=parseInt(mydate.getMonth()+1)<10?"0"+(mydate.getMonth()+1):mydate.getMonth()+1;
      var myday= mydate.getDate();
      var myweekday=mydate.getDay();
   	  var myHours = parseInt(mydate.getHours())<10?"0"+(mydate.getHours()):mydate.getHours();
      var myMinutes = mydate.getMinutes()<10?"0"+mydate.getMinutes():mydate.getMinutes();
      var mySeconds = parseInt(mydate.getSeconds())<10?"0"+mydate.getSeconds():mydate.getSeconds();
      if(myweekday == 0)
      weekday=" 星期日 ";
      else if(myweekday == 1)
      weekday=" 星期一 ";
      else if(myweekday == 2)
      weekday=" 星期二 ";
      else if(myweekday == 3)
      weekday=" 星期三 ";
      else if(myweekday == 4)
      weekday=" 星期四 ";
      else if(myweekday == 5)
      weekday=" 星期五 ";
      else if(myweekday == 6)
      weekday=" 星期六 ";
     datetime.innerHTML=year+"年"+mymonth+"月"+myday+"日 "+myHours+":"+myMinutes+":"+mySeconds+" "+weekday;
  	 setTimeout("setTime()",1000);
  }
  </script>
</html>