`
A牛哥哥
  • 浏览: 150035 次
社区版块
存档分类
最新评论
阅读更多

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>
  • 大小: 7.5 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics