利用javaScript实现时间实时更新

话不多说,贴代码,有什么不足的地方请告诉我,谢谢!或者有什么不懂得地方可以留言

function getTime(){
	str = "当前时间为:"
	var p = document.getElementById("timeP");
	time =  new Date();
	year = time.getFullYear();
	month = time.getMonth() + 1;
	day = time.getDate();
	hour = time.getHours();
	minutes = time.getMinutes();
	seconds = time.getSeconds();
	str = str + year +"-"+ month +"-"+ day + " " +hour+":"+minutes+":"+seconds;
	
	p.innerText = str;

	setTimeout(getTime,1000);
}


window.onload = function(){
	getTime();
}




	
	Document	
	
	


		



你可能感兴趣的:(WEB)