获取当前时间的代码

如标题:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> Test  Date Now </title>
  <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;  
					
					//console.info(t);
			}, 1000); 

		};
</script>

 </head>

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

  

 

posted @ 2018-03-12 15:11  xh_Blog  阅读(1196)  评论(0编辑  收藏  举报