user157733
user157733

Reputation: 579

Time picker problem with OS4?

I have an app which I am updating to OS4. In this I use a time picker. From this I want to get an hour and minute as an integar. This is the code I used previously for this...

NSDate *selected = [timePicker date];

NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit| NSMinuteCalendarUnit |NSSecondCalendarUnit;


NSDateComponents *compsDur = [gregorian components:unitFlags fromDate:selected];
int hDur = [compsDur hour];
int mDur = [compsDur minute];
int sDur = [compsDur second];

[gregorian release];

Now all was working fine here. My problem is that when I update to OS4 if I change my phones time settings say from the UK to the US I get a random value not what the user has entered.

To give you a specific example, on UK time I set the time for 1 minute, I get a return value for mDur as 1. If I then change my phone to New York time I get 19 hours and 6 minutes? What's going on?

Upvotes: 0

Views: 369

Answers (1)

James
James

Reputation: 5820

I think this might be related to an undocumented change to the UIDatePicker in iOS4 where it defaults to (what I think is) GMT as the time zone.

You can set the time zone of the UIDatePicker to the system time zone so the user gets the expected experience.

yourDatePicker.timeZone = [NSTimeZone systemTimeZone];

Upvotes: 1

Related Questions