显示服务器时间并一直显示
获取服务器端时间并不停网页在显示上function createXMLHttpRequest () {
var request = false;
if(window.XMLHttpRequest) {
request = new XMLHttpRequest();
if(request.overrideMimeType) {
request.overrideMimeType('text/xml');
}
} else if(window.ActiveXObject) {
var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
for(var i=0; i
try {
request = new ActiveXObject(versions[i]);
if(request) {
return request;
}
} catch(e) {
//alert(e.message);
}
}
}
return request;
}
var http = createXMLHttpRequest();
http.open("HEAD", ".", false);
http.send(null);
var curDate = new Date;
var offsetTime = curDate - Date.parse(http.getResponseHeader("Date"));
setInterval(function()
{
curDate.setTime(new Date - offsetTime);
document.getElementById("spnTime").innerHTML = curDate.toLocaleString();
}, 1000);