2

Does anyone know how to get the timezone based on a users state/province and country selection?

Nugs
  • 5,503
  • 7
  • 36
  • 57
  • 1
    Is this for a windows app or a web app? – James Johnson Nov 16 '11 at 18:41
  • web app. My user sets their region, country etc and i need to grab the correct time zone for that location. – Nugs Nov 16 '11 at 18:43
  • possible duplicate of [I need a mapping list of cities to timezones- best way to get it?](http://stackoverflow.com/questions/262264/i-need-a-mapping-list-of-cities-to-timezones-best-way-to-get-it) – Dan J Nov 16 '11 at 18:43
  • 1
    Uuuummm, how is it "difficult to tell what is being asked here"?? – Nugs Nov 16 '11 at 18:52
  • 1
    I think i was pretty clear... I need a users timezone based on there region and country... – Nugs Nov 16 '11 at 18:53
  • I think the only way to really do this is a database of all the countries with their states or provinces and what time zone they're in. So this really isn't a programming question, it's more of a "where do I get this data" question (there's a few suggestions listed already).. Most websites just have users select their timezone from a dropdown list, anything wrong with this approach? – Mike Christensen Nov 16 '11 at 18:56
  • 4
    I disagree with closing the question as "not a real question", but I do think it's a dupe. – Mike Christensen Nov 16 '11 at 19:00

3 Answers3

2

You can use the public time zone database tz database

Here is an example for C# http://www.codeproject.com/KB/dotnet/Using_time_zones_in_NET.aspx

// Get the local computer's time zone
TzTimeZone zone = TzTimeZone.CurrentTimeZone;

// Get a common time zone
zone = TzTimeZone.ZoneUsEastern;

// Get a zone in the time zone database
zone = TzTimeZone.GetTimeZone(TzConstants.TimezoneEuropeMoscow);
parapura rajkumar
  • 24,045
  • 1
  • 55
  • 85
0

I would suggest looking at http://www.geonames.org/ - they provide a number of RESTful web services for geo-location and the like. You'd likely have to use one of their services to get a lat/lon for the state/province, then the actual timezone service (which gives the timezone at a given lat/lon).

Paul Kirby
  • 570
  • 4
  • 23
0

Since this is a web app, you won't be able to use TimeZoneInfo or any of the built in utilities. I would look into using a service of some sort, like Yahoo Web Services API or the Google Maps API.

Chuck D
  • 1,629
  • 2
  • 16
  • 32
James Johnson
  • 45,496
  • 8
  • 73
  • 110