tags:

views:

92

answers:

3

How can i do this?

EDIT: I'm not sure if this would work but sometimes you get those annoying pop-ups that tell you what city/suburb you're in (usually for dating sites) - could we somehow extrapolate from that data what the time is??? Is this data based on a reverse IP lookup??

Any suggestion code to get me started (I don't really know what I'm looking for - just the end result i want!) would be fantastic!

Thanks.

+2  A: 

Use the Geo Location API to get the user's location, then lookup their local time via some web service like this.

Realise that you have to rely on the time kept on a server somewhere. If your server has the local time to a reasonable degree of accuracy, you could just offset your server's time to match the user's time-zone.

Evil Pigeon
By the way, I think only Opera (and Firefox through a plugin) support the geolocation api. EDIT: maybe chrome 5 too.
Artefacto
Hmm, other than that you'd have to rely on a less reliable service such as GeoIP or user input. Many sites allow users to configure a time zone in their profile. If you're looking at giving each user a login, this would be ideal.
Evil Pigeon
Sounds like a plan ... smell like plan ... deserve cookies !
Prix
Thanks Evil Pigeon!!!!
Simon
Note, GeoIP services are inaccurate, and worse, users are sometimes behind proxies that may be hundreds of miles away, or further. Some of the most active IPs in the logs of a site I maintain turned out to be a pool of proxies for a major satellite internet company. Using GeoIP to guess timezone isn't a terrible idea, but it's best to let your users override it.
Frank Farmer
Thanks for the heads up - will make sure to have a user override.
Simon
+1  A: 

Using JavaScript, dateObject.getTimezoneOffset() can return the offset between the users local time and the GMT in minutes.

Scuzzy
Thanks but will this get the user's computer's time though or the physical time in that location???
Simon
A: 
vlad b.