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);