views:

291

answers:

3

Hello,

I'm using .NET and I'm able to geolocate user city by IP.

Is there easy way to get user timezone by long. and lat. or city name?

I wonder how facebook is doing it?

Thank You

A: 

If the code is executed on the user PC you can use TimeZone.CurrentTimeZone property to get the time zone of the current computer.

I believe that websites use PHP or JavaScript to get the user time zone, or simply they ask the user, for example when he/she registers a new account.

Adrian Faciu
A: 

You can get a list of timezones from the system and compare it to the city name:

http://msdn.microsoft.com/en-us/library/bb397781.aspx

Which is fragile.

Alternatively there are a few web services out there you can use, passing it long/lat and it gives you timezone, but that means you're tethered to the third part web service.

Michael Shimmins
+1  A: 

There is a web service you can use to get the timezone by city or longitude and latitude:

http://www.earthtools.org/webservices.htm#timezone

Cocowalla
That isn't really a full time zone IMO. It's a current offset from UTC - which means you don't know when DST will change etc. It's a shame it doesn't give an Olsen name.
Jon Skeet
True, but the response does include the local time (taking into account daylight savings time, if it's in effect), UTC time, and whether or not daylight savings time is in effect - probably enough for many purposes. An example: http://www.earthtools.org/timezone-1.1/57.09/02.05
Cocowalla