The question is as it sounds - how to retrieve the client user's time zone based on their browser input? If it matters, server side, J2EE is used - but I don't think that really matters in this case. Right now, HTTP is the protocol, it may use HTTPS when it goes live.
-
This would be useful to have the browser expose to applications, and seems that it would not expose much risk. – pearcewg Mar 10 '09 at 14:13
-
5Duplicate of question 13 (!). http://stackoverflow.com/questions/13/how-can-i-determine-a-web-users-time-zone – user9876 Nov 17 '11 at 18:12
5 Answers
Probably you could use some javascript: http://jeoftp.blogspot.com/2009/03/determine-java-timezone-of-your-web.html

- 111
- 5
Seems somebody hacked some javascript to deduce this but yes, the best way is to let the user decide. But you can use the above link to choose the default for the user.

- 12,871
- 5
- 32
- 36
I'm sure this is a duplicate.
The best way is to ask the user. Time Zone is not sent in the HTML headers, by default. Also consider that a user from one time zone may be visiting another. Which time zone should you use?

- 160,644
- 26
- 247
- 397
-
If it is a duplicate, I couldn't find it on the list of "related questions". There are some questions that are similar, but none asked what I was looking for. – MetroidFan2002 Mar 10 '09 at 14:12
-
I see this is a duplicate of http://stackoverflow.com/questions/743505/how-to-get-time-zone-through-ip-address-in-php, despite the different language. – John Saunders Apr 07 '15 at 16:54
-
That question is very similar, but specifically asks for (and received an answer for) PHP. But that wouldn't work if you were using a stack that wasn't PHP. – MetroidFan2002 Apr 08 '15 at 15:13
-
Totally doesn't matter. It's the exact same answer. It's not about some magic in PHP - it's a question about whether it's possible to get this information through the network stack and the answer is "no". No language is going to solve that problem. – John Saunders Apr 08 '15 at 15:23
-
Even if you use your criteria for duplication, this question was asked beforehand, so the PHP question is the duplicate of this one. – MetroidFan2002 Apr 13 '15 at 16:38
You can also use IP geolocation services like ip2location. They sell a database subscription that will return the timezone in which the IP address is located. Of course, this has a price. A Javascript solution would work but does require that the client supports it.
The geolocation will support any client but can provide the wrong result depending on how the IP block was attributed or if the client is using a proxy server located in a different timezone (most likely an anomysing proxy service). The Javascript solution will support a large variety of client but will return the timezone base on what the computer is set to and not the timezone base on the actual location (traveling user don't always change the time on their computer). So there is no single solution that covers them all.
Using one of these two methods to make a guess and then allowing the user to correct it would be the best approach I would think. If you want to go overkill use both and let the user decide which makes most sense.

- 2,723
- 19
- 27
-
2But, what about proxy servers that mask the origination of the ip address? Wouldn't you only get the timezone of the last proxy server? – MetroidFan2002 Mar 10 '09 at 15:34
-
I've updated the answer pointing out the fact that proxy server would be an issue but only if they are in a different timezone. Thanks for pointing that one out. – Pierre-Luc Simard Mar 10 '09 at 15:45
As stated by Pierre-Luc Simard, which is a very good idea, you can use the IP to deduce that information. Credit goes to him but I'll add another link to a free alternative which is Geolite from Maxmind. There's also a sample code in PHP for the timezones and I'm pretty sure you'll find the equivalent in their Java API.