tags:

views:

61

answers:

2

i want an API of time zones which is based on IP address to be used in php.

A: 

Edit : Looks like we have a similar question : How to get Time Zone through IP Address in PHP

AFAIK there is no API which gives both of you. try out ip2location which can get you the location and then you can use the location to get the timezone.

Shoban
an API would be actually be handy but I suppose you can still ask the user for his timezone.
RageZ
+4  A: 

If this is for use on a website, you can use a client-side script (Javascript) to inform your server-side program about the user's local settings.

The first time a user comes to your site, get javascript to do this:

var d = new Date();
sendAJAX({data : d.getTimezoneOffset(); });

(Of course, replace the "sendAJAX" function with your own JS library or whatever)

The server can then receive that AJAX request and store it in a session, or in the user's record in a database, etc.

You could even store it with their IP address to create your own IP->Timezone mapping, in case someone without Javascript enabled comes along.

nickf
It's still going to be a guess. Each time a region changes between standard time and daylight time, you can be sure at least some people in that region are going to be in the middle of a session somewhere.
Windows programmer
that's a fairly small edge case: someone browsing your site exactly at the moment of daylight savings kicking in (usually 2am). If this is just being used to display times correctly, I'm sure those users would understand if it were out by an hour for that session.
nickf
That's why I worded the comment the way I did. It's a very small percentage of total accesses, but it's still nearly guaranteed to be nonzero.
Windows programmer