Skip to content

Instantly share code, notes, and snippets.

@minodisk
Created August 10, 2011 07:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minodisk/1136327 to your computer and use it in GitHub Desktop.
Save minodisk/1136327 to your computer and use it in GitHub Desktop.
Get server time with AJAX
$(function () {
$.ajax({
type: 'GET',
cache: false,
url: location.href,
complete: function (req, textStatus) {
var dateString = req.getResponseHeader('Date');
if (dateString.indexOf('GMT') === -1) {
dateString += ' GMT';
}
var date = new Date(dateString);
$('#serverTime').text(date.toString());
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment