浏览器获取WEB服务器时间

/*
* 获取XMLHttpRequest对象
*/
function CreateXMLHttpRequest() {
var xmlreq = false;
if (window.ActiveXObject) {
xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlreq = new XMLHttpRequest();
}
return xmlreq;
} /*
* 获取服务端时间,返回DateTime对象
*/
function GetServerDate() {
var xmlhttp = CreateXMLHttpRequest();
var ipaddress = "http://" + location.host + siteSuffix;
xmlhttp.open("HEAD", ipaddress, false);
xmlhttp.setRequestHeader("Range", "bytes=-1");
xmlhttp.send(); //异步的形式向服务器发送请求
var serverDate = new Date(xmlhttp.getResponseHeader("Date"));
return serverDate;
}

  

  WebServerTime = GetServerDate();

 var year = webTime.getFullYear();
var month = webTime.getMonth();
var day = webTime.getDate();
var hour = webTime.getHours();
var m = webTime.getMinutes();
var s = webTime.getSeconds();

  

上一篇:java 多个设备,锁定先后顺序


下一篇:栈和队列的面试题Java实现