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 に答える