You can get the name of the local time zone using:
NSTimeZone *timeZone = [NSTimeZone localTimeZone];
NSString *tzName = [timeZone name];
The name will be something like Australia/Sydney
, or Europe/Zurich
, or America/Denver
. Since it sounds like you might only care about the continent, that might be all you need.
If you need more: Get the official time zone database at http://www.iana.org/time-zones. Download tzdata2013g.tar.gz
(or whatever the most recent version of tzdataYYYYx.tar.gz
is when you're reading this). There's a file in that archive named zone.tab
that gives a lat/long for each time zone, for example:
CH +4723+00832 Europe/Zurich
The +4723+00832
indicates latitude = +47o23", longitude = +8o23".
Update: In some cases (I'm not sure which), the time zone name may be an older-style name like US/Pacific
that isn't listed in zone.tab
. To handle those, also get the file called backward
, which gives translations of older names to current names.
Converting zone.tab
into something your app can use is up to you. The results will be nowhere near as accurate as location services, but will give a general idea. But it's not guaranteed. It will fail in a couple of situations:
The user changes their time zone in Settings. Most users let their phone set the time and zone automatically, but not everyone. If the user changes their time zone, you'll get whatever they want instead of what's accurate.
The device is unable to determine the correct local time zone. Network problems might prevent the phone from setting the time and zone accurately. For example, if the user travels by plane and has network problems when they land, the phone may still show the time zone from their departure location.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…