Reputation: 95
In my iPhone app I want to get system timezone in GMT. Am Using the following code.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"zzz";
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
NSString *timeStamp = [dateFormatter stringFromDate:[NSDate date]];
NSString *timeZoneString=[timeStamp substringFromIndex:3];
[dateFormatter release];
Am getting timezone in GMT form in iOS5 but not in iOS6. How to get timezone in GMT form in iOS6? Please Help!!!
Upvotes: 2
Views: 250
Reputation: 23278
You can check with,
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
in place of,
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
Upvotes: 2
Reputation: 2259
I have revised @ACB's code as there were a few typos , try [dateFormatter setTimezone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
instead of [dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
. This seems to work for me.
I would like to give credit for this answer to @ACB. He/she came up with this technique and I only confirmed it.
Upvotes: 0