rough estimate of the time offset from GMT from latitude longitude

ravun picture ravun · Jun 29, 2009 · Viewed 12.4k times · Source

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).

Answer

balpha picture balpha · Jun 29, 2009
offset = direction * longitude * 24 / 360

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