-
-
Save hellais/4633bfa12c5095588e96 to your computer and use it in GitHub Desktop.
Date Checker with HTTP headers
This file contains 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
<html> | |
<head> | |
<title>Date checker</title> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
// Set this value to the minute tollerance | |
var minute_limit = 30; | |
function get_date_header(address) { | |
// Address must not violate SOP, if it | |
// does then browsers will not allow to read | |
// the "Date" header. | |
var client = new XMLHttpRequest(); | |
client.open('GET', address, false); | |
client.send(null); | |
console.log(client); | |
var hdate = client.getResponseHeader("Date"); | |
return hdate; | |
} | |
date_header = get_date_header("/date.html"); | |
var server_date = new Date(date_header); | |
var now = new Date(); | |
var m_offset = (now - server_date)/(60*1000); | |
if (m_offset > minute_limit) { | |
document.write("Your clock is off by "+m_offset+" minutes"); | |
} else { | |
document.write("Your clock is synchronized to at least "+minute_limit+" minutes"); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment