js获取服务器时间戳

<!DOCTYPE html>

<html>

<head>

<title>ajax</title>

</head>

 

<body>

<script src="js/dui.js"></script>

<script>

// 方法一

ajax('/', function (data, obj) {

  alert(obj.getResponseHeader("Date"));

});

 

// 方法二

var xmlhttp = null;

 

if (window.ActiveXObject) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

else xmlhttp = new XMLHttpRequest();

 

xmlhttp.open('get', "/", false);

xmlhttp.setRequestHeader('If-Modified-Since', 'q');

xmlhttp.send();

 

var timestr = xmlhttp.getResponseHeader('Date');

var date = new Date(timestr);

alert(date);

</script>

</body>

</html>

 

 

 

var utlis = (function (win, doc) {
var module = {};

// 获取服务器时间
module.servertime = function (options) {
var xmlhttp = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : xmlhttp = new XMLHttpRequest();

xmlhttp.open('get', '/', false);
xmlhttp.setRequestHeader('If-Modified-Since', 'q');
xmlhttp.send();

return new Date(xmlhttp.getResponseHeader('Date'));
};

return module;
})(window, document);

posted @ 2014-10-29 22:02  baiezone  阅读(1878)  评论(0编辑  收藏  举报