This would be useful when I have a user's address or zipcode, and used that to find their timezone so they don't have to enter it in a separate field.
views:
1408answers:
5I recall once having a data set that provided zip code to time zone information. This data set probably came from one of: USPS, the Census, or NOAA (for weather forecasts).
Sorry I can't provide more information than that.
This has been discussed recently on the Time Zone mailing list run by A D Olson, who created the Olson database of time zone names and rules. There isn't a single, simple source (which isn't surprising, really; there are lots of countries, and lots of different rules).
One of the locations for some of the information that I came across and bookmarked is www.geonames.org. This was particularly during September 2008. You can download the mailing list archive by anonymous FTP from Elsie (about 17 MB, dating back into the early 90s, if not somewhat before). The emails mention ESRI as a source of information.
I would recommend against trying to deduce the timezone from the users zip code.
To the user the question:
"What is your zip code" isn't likely to change very often.
It will change, but probably less frequently then the question "what time zone are you in".
For example, if the user travels somewhere, their zip code hasn't changed, but their timezone has.
If you try to ask "what zip code are you in?", the user probably won't know, particularly if he or she is traveling.
Instead, I would try and figure out what the timezone is directly.
Most platforms will give you a way to do this.
For example, if you are writing desktop software for .NET you can do this by
- Getting the current timezone using the TimeZoneInfo class, or
- Sending all times from the server to the client in UTC time, and then use DateTime.ToLocal Time to convert the UTC time into local time.
Or, if you are writing web software, then you can get the timezone from the user's web browser using Java Script and submit it to the server.
Take a look at the following date functions:
http://www.w3schools.com/jsref/jsref_obj_date.asp
You can deduce the timezone using various date functions.
There is a method "getTimezoneOffset", but it doesn't give a +/-. So for example it would give "1" for both +1 and -1 GMT, which could be a problem.
What you can do, however, is send a known date from the server, convert that to local time using the conversion methods, and then send the result back up to the server.
When you send the known date down, you should probably send it as a millisecond offset. That way you can avoid any culture issues (dates are formatted differently in different places).
There are Win32 functions that will give you the timezone, and I am sure there are probably Unix, Mac, and Java APIS that will do the same thing.
Yes - you can use a geocoder such as geonames.org to get latitude,longitude from the zipcode (the geocoder may also include timezone or have a separate webservice for that).
If your geocoder doesn't do it, then given the latitude and longitude you can get a timezone from this webservice:
You could use GeoIP to get the lat long from their IP address, thus obtaining their lat/long for translating into their timezone.
You can call their webservice, or you can download the database yourself.
There are caveats, however.
- If the user has a proxy server you'll get their proxy IP.
- Some IP's do not translate