.jsp的时间控件与服务器时间同步

将web页面的时间控件与服务器时间同步

//时间初始化=  =
	<% Date date = new Date(); %>
	var dt = new Date();
	dt.setTime(<%=date.getTime()%>);
	var t= null;
	t = setTimeout(showTime,100);
	function showTime(){
		clearTimeout(t);
		//var y = dt.getFullYear();
		//var mt = parseInt(dt.getMonth())+1;
		//var date = dt.getDate();
		var h = dt.getHours();
		var m = dt.getMinutes();
		//var s = dt.getSeconds();
		//if(mt<10)mt="0"+mt;
		//if(date<10)date="0"+date;
		if(h<10)h="0"+h;
		if(m<10)m="0"+m;
		//if(s<10)s="0"+s;
		//var times = y+'-'+mt+'-'+date+' '+h+':'+m;
		$(".nowTime_h").val(h);
		$(".nowTime_m").val(m);
		$(".nowTime").val(h+':'+m);
		// 超时变色--
		//var isOut = needfinishTime-new Date();
		//if (isOut<0) {
		//	$(".nowTime").css("color","red");
		//}
		dt.setTime(dt.getTime() + 1000);		
		t = setTimeout(showTime,1000);
	}
	```

你可能感兴趣的:(.jsp)