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]; 
}

谢谢。

4

1 回答 1

1

您可以使用,

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

或者,

+ (id)timeZoneForSecondsFromGMT:(NSInteger)seconds

在你的情况下,

[calendar setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8*60*60]];
于 2011-08-17T08:32:21.777 回答