1. 程式人生 > >獲取當前時間的代碼

獲取當前時間的代碼

fun 獲取 w3c 當前 load etsec win 程序 onload

如標題:

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

  

獲取當前時間的代碼