Question

I am having a problem with calculating time difference between two timeZones.

If I am at location A I know the latitude and longitude and the current time. I go to location B I know the latitude and longitude and the current time.

How to calculate the time difference between the two current points .. (in UTC)

Was it helpful?

Solution

Firstly get a database or library that converts lat/long to get the country and state/province. Then use the NSTimeZone class to retrieve the timezone for a particular country. You can purchase such databases from many sites, ie: http://www.ip2location.com/

To do the actual conversion you would do something like this:

NSTimeZone *sourceTimeZone =
    [NSTimeZone timeZoneWithAbbreviation: @"GMT"];
NSTimeZone *destinationTimeZone =
    [NSTimeZone timeZoneWithAbbreviation: @"EST"];

NSInteger sourceSeconds =
    [sourceTimeZone secondsFromGMTForDate:date];
NSInteger destinationSeconds =
    [destinationTimeZone secondsFromGMTForDate:date];
NSTimeInterval interval = destinationSeconds - sourceSeconds;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top