Изменение часового пояса - PullRequest
       13

Изменение часового пояса

0 голосов
/ 17 августа 2011

Я занимаюсь разработкой target-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 Ответ

1 голос
/ 17 августа 2011

Вы можете использовать,

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

OR

+ (id)timeZoneForSecondsFromGMT:(NSInteger)seconds

Что будет в вашем случае,

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