異なるタイムゾーンにある特定の時刻にサーバーデータにアクセスしています この日付とデバイス時間を比較し、ユーザーに最新の更新情報を表示する必要があります。iphoneサーバーからローカルデバイスへのNSDateの変換時間と比較
私は以下のようになっています。
enter code here
NSString *localString = @"2012-02-10T23:53:46+0000";
NSString *serverTime = @"2012-02-11T06:17:39+0000";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
NSDate* sourceDate = [dateFormatter dateFromString:serverTime];
NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate];
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];
NSLog(@"Source OFFSET %i",sourceGMTOffset)
NSLog(@"Desti OFFSET %i",destinationGMTOffset);
NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
NSDate* destinationDate = [[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate] ;
NSString *thePubDate = [dateFormatter stringFromDate:destinationDate];
NSLog(@"Result : %@",thePubDate);
[dateFormatter release];
し、以下のように結果を得る.. 2012-02-10 23:54:29.296テスト[309:207]ソースは0 2012-02-10 23 OFFSET: 54:29.297テスト[309:207]デスティOFFSET -28800 2012-02-10 23:54:29.298テスト[309:207]結果:1969-12--2147483629 -596:-31:-23 誰でも私に解決策を教えてください。 – Avinash
3分またはそれ以上の時間ごとにデータを更新したいですか。 –
私は特定の間隔の後にデータにアクセスする必要があります – Avinash