2011-08-17 97 views
0

我在做Objective-C(iOS)开发。我可以知道如何将GMT +0的默认时区更改为GMT +8。 GMT +8是针对新加坡的。更改时区

这里是我的代码:

- (IBAction)dateChanged { 
    NSDate *choice = [datePick date]; 
    NSString *words = [NSString alloc initWithFormat:@"%@", choice]; 
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You have selected:" message:words delegate:nil cancelButoonTitle:@"OK" otherBUttonTitles:nil, nil]; 
    [alert show]; 
    [alert release]; 

    [words release]; 
} 

感谢。

回答

1

可以使用,

NSCalendar *calendar = [NSCalendar currentCalendar]; 
    [calendar setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; 

OR,

+ (id)timeZoneForSecondsFromGMT:(NSInteger)seconds 

,这将是你的情况,

[calendar setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8*60*60]];