views:

739

answers:

2

Is there a way to estimate the offset from GMT (or time zone) from a latitude/longitude? I've seen geonames, but this would need to work long term and we don't really want to rely on a web service. It'd just be used for determining whether to display "today" or "tonight" when giving information to various users so it wouldn't need to be too accurate (an hour or two off wouldn't be bad).

+5  A: 
offset = direction * longitude * 24 / 360

where direction is 1 for east, -1 for west, and longitude is in (-180,180)

balpha
That's pretty cool, didn't think it'd be that simple, but so far it seems pretty accurate.Thanks.
ravun
@ravun, this is correct by defiition given that a) the earth has 360 degrees of longitude, and b) rotates through that 360 degrees in 24 hours. (-:
Rob Wells
It's *reasonably* correct given that time zones borders are usually put on country borders. Otherwise, I'd have to set my watch each day when going to work, and again when going home :-) Also, daylight saving time depends on local legislation. But for the today / tonight question, it should suffice.
balpha
The main area to watch for issues is in the Pacific, where there are some fairly extreme contortions in time zone boundaries. Still, even those will get you to within a couple of hours.
Jonathan Leffler
A: 

Let make a loop: Here is a continuation of this question at what the punters at ST calls "the hyphened site" http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_25465106.html It has two methods, one using yahoo/google geocoding, the other using usno.navy.mil for US only

mplungjan - techno-agnost

mplungjan