Reputation: 8267
Assuming I have a point in time, represented by
NSDate* now = [NSDate date];
for example: 2012-11-07 13:44:55 +0000 (the local time of the device)
I also have an array of countries each country has a name, and geo coordinates (log,lat)
for example: England,51.5, -0.116667
Q: how would one calculate and convert the above date-time into the current equivalent time in a specific country?
(As a side note, I rather have something local and not calling external API)
Upvotes: 2
Views: 1076
Reputation: 1541
Get a list of time zones available by,
[NSTimeZone abbreviationDictionary]
This would return something of this sort,
EST = "America/New_York";
GMT = GMT;
GST = "Asia/Dubai";
HKT = "Asia/Hong_Kong";
HST = "Pacific/Honolulu";
ICT = "Asia/Bangkok";
IRST = "Asia/Tehran";
IST = "Asia/Calcutta";
JST = "Asia/Tokyo";
KST = "Asia/Seoul";
MDT = "America/Denver";
MSD = "Europe/Moscow";
MSK = "Europe/Moscow";
Now use this time zone abbreviation key, say MSD for Moscow, to get the number of seconds that is offset in Moscow's time zone from the GMT.
NSInteger no_of_seconds = [[NSTimeZone timeZoneWithAbbreviation:@"MSD"] secondsFromGMT];
The 'no_of_seconds' can now be added to the current date to get the date of the desired location, in this case Moscow,
[NSDate dateWithTimeIntervalSinceNow:no_of_seconds]
Upvotes: 3