Does anybody know how to get the olson zoneinfo by client IP?i tried some free IP service,but what they return is something like "New York" instead of "America/New_York".
2 Answers
Try geoip (http://www.maxmind.com/), it is not free but works well and databases updates very often. Then you can get time zone info from com.maxmind.geoip.timeZone by country and region from client ip
String timeZoneByCountryAndRegion(String country, String region)

- 333
- 1
- 8
You need to separate this into two steps.
There are many services that can get the IANA/Olson time zone identifier from latitude and longitude coordinates. See: How to get a time zone from a location using latitude and longitude coordinates?
To get the latitude and longitude, you should try not to rely on IP Geolocation. Many web browsers are running on actual devices that can report their real coordinates, such as on mobile phones. You can fall back to IP geolocation if you have to, and there are many services that attempt to do that.
The problem with IP geolocation is that you are not guaranteed accuracy. Many people access the internet through proxy servers, VPNs, or other mechanisms where the IP you are looking up may not actually be related to their location at all.

- 1
- 1

- 230,703
- 74
- 448
- 575
-
Yes,This is a very constructive opinions,but if i get location first,then use location to get olson tz,it occurs others problem.fore more detail ,please see this post:http://stackoverflow.com/questions/18610756/does-anybody-used-html5-geolocation-in-production-server-before?noredirect=1#comment27393400_18610756 – Chailie Sep 04 '13 at 10:03
-
That's why you should not be trying to do it by IP address at all. You've created an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) for yourself by assuming IP was the right approach. If you want to know the users time zone, then ask that question. Or search and you will see that it has been asked many times before. I've answered it [here](http://stackoverflow.com/a/16526897/634824), for example. – Matt Johnson-Pint Sep 04 '13 at 12:33
-
Also, you tagged your question as `Java` so I didn't know you were even in a web application. Did you mean `JavaScript`? Are you looking for a browser-based solution? – Matt Johnson-Pint Sep 04 '13 at 12:42
-
Yes,i am looking for a browser-based solution,my requirement is just get olson timezone info when user open my application in browser.my problem is i can't get olson timezone in a simplicity way.for using what implementation,e.g javascript or java or whatever,that's not too important for me. and yes,there are so many similar question in stackflow,but most of them is not saying get olson timezone.so anyway,my only question is how to get olson timezone when user open web application in mainstream browser. – Chailie Sep 05 '13 at 03:05
-
Yes,i just read it and i am trying the "option 1",but i found the drop list implementation of https://github.com/dosx/timezone-picker is a little complex for my project,i think my user won't hope to see a such "fancy" drop picker,i hope to see a simple HTML drop list of timezone – Chailie Sep 05 '13 at 04:07
-
So my solution is add one timezone drop list in UI,by default,select a default option by using the js lib of jsTimezoneDetect,beside this drop list,i also will add one button next to the drop list,user can click it to locate him by using HTML 5 geolocation and google map API. – Chailie Sep 05 '13 at 04:11
-
That sounds like a good plan. You may also be interested in using the technique I describe [here](https://bitbucket.org/pellepim/jstimezonedetect/issue/73) for browsers that support it. – Matt Johnson-Pint Sep 05 '13 at 04:26