3

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.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
theburningmonk
  • 15,701
  • 14
  • 61
  • 104

5 Answers5

9

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.

Community
  • 1
  • 1
Adam Robinson
  • 182,639
  • 35
  • 285
  • 343
3

You can get both a user's timezone and the UTC Offset from an IP address with ipapi.co :

https://ipapi.co/8.8.8.8/timezone
> America/Los_Angeles

https://ipapi.co/8.8.8.8/utc_offset
> -0800
Francis
  • 266
  • 3
  • 3
0

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

Alex Polkhovsky
  • 3,340
  • 5
  • 29
  • 37
  • 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 May 24 '10 at 16:57
0

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
  • 508
  • 2
  • 10
0

Using restSharp.org and my service ipdata.co

var client = new RestClient("https://api.ipdata.co?api-key=test");
var request = new RestRequest("1.1.1.1", Method.GET);
request.AddHeader("Content-Type", "application/json");
IRestResponse response = client.Execute(request);
var content = response.Content; // raw content as string
RestResponse<Ip> response2 = client.Execute<Ip>(request);
var time_zone = response2.Data.time_zone;
Jonathan
  • 10,792
  • 5
  • 65
  • 85