2

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!!!

4

2 回答 2

2

你可以检查,

[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; 

代替,

[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
于 2012-12-27T04:37:32.180 回答
0

我已经修改了@ACB 的代码,因为有一些拼写错误,尝试[dateFormatter setTimezone:[NSTimeZone timeZoneForSecondsFromGMT:0]];而不是[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];. 这似乎对我有用。

我想将这个答案归功于@ACB。他/她想出了这种技术,我只是确认了它。

于 2012-12-27T04:35:53.243 回答