js获取服务器时间

来源:互联网 发布:mac 升级后切换花屏 编辑:程序博客网 时间:2024/05/20 13:06


通过ajax获取response headers 的date值,不过,在chrome 中看到应该是格林威治时间,比北京时间小8个小时

代码:

var importJs=document.createElement('script')  //在页面新建一个script标签importJs.setAttribute("type","text/JavaScript")  //给script标签增加type属性importJs.setAttribute("src", 'http://libs.baidu.com/jquery/1.9.1/jquery.min.js') //给script标签增加src属性, url地址为cdn公共库里的document.getElementsByTagName("head")[0].appendChild(importJs)//把importJs标签添加在页面$.ajax({type:"OPTIONS",url:"/",complete:function(x){console.log(x.getResponseHeader("Date"))}})

前面是因为有些页面不提供jQuery文件,因此导入jQuery文件供方法调用