views:

291

answers:

4

Is there a way to find the time zone a user is in when all I have is their IP address? I'm looking for the time offset I need to apply to the server time in order to find the time for the user's location.

+5  A: 

You'll need to attempt to determine the location (which is far from 100% accurate). See this question about doing just that.

See this question about translating a zip code into time zone (though that, again, is not 100% fool proof).

The short version is: it's complicated. You'll have to use a third-party service that maintains a database of IP masks to locations, then use the location determined there to determine the time zone.

It's far more reliable to have the client simply send the time zone (or UTC offset) when it connects.

If this is a web application, see one more question about using JavaScript to determine the client time zone.

Adam Robinson
A: 

MaxMind offers a database you can purchase that will help you with your task: http://www.maxmind.com/app/city

LymanZerga
we already use MaxMind's free GeoIP.dat database for country lookup but it doesn't give us the timezone. The timezone text file (http://www.maxmind.com/timezone.txt) posted on their site ain't that useful either
theburningmonk
A: 

ip2nation provides an SQL database that you can query to geolocate an IP address:
http://www.ip2nation.com/ip2nation/Download

With the country code in hand, you can retrieve a country's time zone possibly by querying another database or library.

Propeng
A: 

You can also use the IP Geolocator dll built by Spiderweb Logic. It is rather cheap - and a time-saver (a small one-time fee).

It calls a web service built on MaxMinds free version of the database... Or you can use it to call (and cache) data from an existing MaxMind web service.

This is a wrapper for a few free services - and wraps MaxMind's service as well - if needed. It handles all caching etc...

It also wraps some services to do conversion of time for time-zone and handles formatting of time for several country-specific formats.

It is really cool...

Robert Fuess