goldenmean
goldenmean

Reputation: 18976

finding the time zone from which a browsers connection to a Web server

I am not into web (client/server)application development, but had this question for sometime -

If some web browser (IE/Firefox) makes a connection to some website, is it possible for the web server to find out the timezone of the client, or current local time of the client place, and display the same on the page.

If yes then how is the time zone found out? Does the client play any role in this process or server alone can do this task without any input from client?

-AD

Upvotes: 3

Views: 1091

Answers (2)

nickf
nickf

Reputation: 546085

The server can not directly tell the timezone of a client connection, but a little trick you can do is use Javascript on the client side to determine the timezone and then report it back to the server in some way. This could be by setting a cookie (the server has access to the cookies), an AJAX request, or by changing a link href to insert the timezone into a GET parameter.

Upvotes: 2

flesh
flesh

Reputation: 23935

Yes. Use something like:

<script type="text/javascript" language="javascript"> 
var tz =(new Date).getTimezoneOffset()/-60; 
</script>

See also:

http://www.willmaster.com/library/javascript/determining-your-visitors-time-zone.php http://www.tommylacroix.com/2008/02/25/detect-timezone-with-javascript/ http://www.webmasterworld.com/forum13/3922.htm

Upvotes: 4

Related Questions