2011-08-17 99 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]];