Skip to content

Instantly share code, notes, and snippets.

@timrwood
Created October 15, 2012 16:20
Show Gist options
  • Save timrwood/3893376 to your computer and use it in GitHub Desktop.
Save timrwood/3893376 to your computer and use it in GitHub Desktop.
Syncing local clock with server time
var clientNow = moment(),
serverNow;
$.ajax('/gettime', function (resp) {
serverNow = moment(resp);
});
function syncedMoment(i, f) {
return moment(i, f).subtract('milliseconds', clientNow - serverNow);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment