Friday, 7 July 2017

Determine a User's Timezone

Question: Is there any standard way for a Web Server to be able to determine a user's timezone within a web page? Perhaps from a HTTP header or part of the user-agent string?

Solution:  To submit the timezone offset as an HTTP header on AJAX requests with jQuery.


$.ajaxSetup({
    beforeSend: function(xhr, settings) {
        xhr.setRequestHeader("X-TZ-Offset", -new Date().getTimezoneOffset()/60);
    }
});

No comments:

Post a Comment