网页获取网络时间
const getNetTime = () => {
return new Promise((resolve, reject)=> {
var xhr = new XMLHttpRequest();
if( !xhr ){
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.open("HEAD",location.href,true);
xhr.onreadystatechange=function(){
if( xhr.readyState == 4 && xhr.status == 200 ){
resolve(xhr.getResponseHeader("Date"));
}
}
xhr.send(null);
})
}
getNetTime().then(res => {
console.log(res,"网络时间")
})