Как указать часовой пояс в UIDatePicker

- (IBAction) buttonPressed {
NSDate *selected = [datePicker date];
NSString *message = [[NSString alloc] initWithFormat:@"The date and time you selected is: %@", selected];
UIAlertView *alert = [[UIAlertView alloc]
                      initWithTitle:@"Date and Time Selected" message:message delegate:nil cancelButtonTitle:@"Yes, I did!" otherButtonTitles:nil];
[alert show];
[alert release];
[message release];

Итак, мой вопрос следующий ... Как я могу указать часовой пояс с помощью Datepicker в Objective C? теперь, если я выберу некоторые значения из DatePicker и нажму кнопку, которая отображает предупреждение - время неверное. Вероятно, это из-за неправильного часового пояса, но я не уверен. Что ж, любые идеи были бы отличными. На картинке ниже вы можете видеть, что я выбрал 14:14 (14:14), но альтернативный говорит, что сейчас 11:14, а часовой пояс +000

ОБНОВЛЕНИЕ 1 Я добавил несколько изменений в свой код, но все еще ничего ...

- (IBAction) buttonPressed {
NSDate *selected = [datePicker date];       
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];    
NSTimeZone *tz = [NSTimeZone systemTimeZone];
[dateFormatter setTimeZone:tz];
NSString *formattedDate = [dateFormatter stringFromDate:selected];
NSString *message = [[NSString alloc] initWithFormat:@"The date and time you selected is: %@", formattedDate];
UIAlertView *alert = [[UIAlertView alloc]
                      initWithTitle:@"Date and Time Selected" 
                      message:message delegate:nil cancelButtonTitle:@"Yes, I did!" otherButtonTitles:nil];
[alert show];
[alert release];
[message release];
[dateFormatter release];
9
задан yuji 5 March 2012 в 00:08
поделиться

0 ответов