Sunday, 4 March 2012

Solving Time Difference problem with GMT


                    NSDate *resultDate = [format dateFromString:strDate];

                    NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
                    NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
                    
                    NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:resultDate];
                    NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:resultDate];
                    NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
                    
                    NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:resultDate] autorelease];
                    [format setDateFormat:@"MMM dd yyyy, HH:mm"];
                    NSString *strResultDate = [format stringFromDate:destinationDate];

No comments:

Post a Comment