문제

두 시간 사이의 시차를 계산하는 데 문제가 있습니다.

내가 위치에 있다면 AI는 위도와 경도와 현재 시간을 알고 있습니다. 나는 위치로갑니다. BI는 위도와 경도와 현재 시간을 알고 있습니다.

두 지점 사이의 시차를 계산하는 방법 .. (UTC)

도움이 되었습니까?

해결책

먼저 LAT/Long을 전환하여 국가 및 주/지방을 확보하는 데이터베이스 또는 라이브러리를 얻습니다. 그런 다음 nstimezone 클래스를 사용하여 특정 국가의 시간대를 검색하십시오. 많은 사이트에서 이러한 데이터베이스를 구입할 수 있습니다. http://www.ip2location.com/

실제 변환을 수행하려면 다음과 같은 작업을 수행합니다.

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

NSInteger sourceSeconds =
    [sourceTimeZone secondsFromGMTForDate:date];
NSInteger destinationSeconds =
    [destinationTimeZone secondsFromGMTForDate:date];
NSTimeInterval interval = destinationSeconds - sourceSeconds;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top