When i convert the time from my Xcode iPhone simulator my code working fine and the output as it showing here:
2014-02-12 18:11:52 +0000
Local Time Zone (Europe/London (GMT) offset 0)
0
but when i try using my app on my iPhone 5 the output changed to
1970-01-01 12:00:00 am +0000
Local Time Zone (Europe/London (GMT) offset 0)
0
i am using xcode 5.0 and iOS 7
-(NSDate *)convertGMTtoLocal:(NSString *)gmtDateStr {
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSTimeZone *gmt = [NSTimeZone systemTimeZone];
[formatter setTimeZone:gmt];
NSDate *GMTTime = [formatter dateFromString:gmtDateStr];
NSTimeZone *tz = [NSTimeZone localTimeZone];
NSLog(@"%@",tz);
NSInteger seconds = [tz secondsFromGMTForDate: GMTTime];
NSLog(@"%ld",(long)seconds);
NSLog(@"%@",[NSDate dateWithTimeInterval: seconds sinceDate: GMTTime]);
return [NSDate dateWithTimeInterval: seconds sinceDate: GMTTime];
}
Thanks,