获取当前时间的代码

如标题:

<!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>

  

原文地址:https://www.cnblogs.com/xh_Blog/p/8549412.html