js动态获取当前系统时间,以yyyy-MM-dd hh:mm:ss显示在页面上

 

function getTime() {
	    var date = new Date();
	    var month = date.getMonth() + 1;
	    var strDate = date.getDate();
	    var hour = date.getHours();
		var min = date.getMinutes();
		var sec = date.getSeconds();
		
		 if (month >= 1 && month <= 9) {
		        month = "0" + month;
	    }
		 if (strDate >= 0 && strDate <= 9) {
		        strDate = "0" + strDate;
	    }
		 if (hour >= 0 && hour <= 9) {
		        hour = "0" + hour;
	    }	
         if (min >= 0 && min <= 9) {
		        min = "0" + min;
	    } 	
         if (sec >= 0 && sec <= 9) {
		        sec = "0" + sec;
	    }
	    var time = date.getFullYear() + "年" + month + "月" + strDate
	            +"日"+ " "+" " + hour+":"+min+":"+sec;
	            
	            
	    document.getElementById('mytime').innerHTML = time;        
	    return currentDate;
	}
	//一次性定时器  setTimeout()
	var id = setInterval('getTime()',1000);	

 

你可能感兴趣的:(java)