Window setInterval() Method
自动增加。
http://www.w3schools.com/jsref/met_win_setinterval.asp
While loading the page get the server time in long and create a Date(millis)
Object with Javascript
.
Then use setInterval()
with 1 sec and display.
In you Jsp
var jsVar= <% dateMillis %>; // server millis
and javascript date formation
var d = new Date();
d.setTime(jsVar); // server millis ex :1332403882588
Then show in JS
var x = document.getElementById("timelable");
x.innerHTML=d.getMilliseconds(); // Modify as per your format
Then
window.setInterval(Yourfunction,milliseconds);##"function_name" 需要双引号
Then in your Yourfunction
add 1 sec to your millis and refresh lable
参考博文 http://stackoverflow.com/questions/19515138/displaying-server-time-on-jsp-page