Created
May 18, 2012 09:09
-
-
Save bububa/2724159 to your computer and use it in GitHub Desktop.
javascript 实时获得服务器上时间
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = new XMLHttpRequest; | |
http.open("HEAD", ".", false); | |
http.send(null); | |
var curDate = new Date; | |
var offsetTime = curDate - Date.parse(http.getResponseHeader("Date")); | |
setInterval(function() | |
{ | |
curDate.setTime(new Date - offsetTime); | |
document.getElementById("spnTime").innerHTML = curDate.toLocaleString(); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment