views:

28

answers:

1

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?

+1  A: 

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];
James Raybould
Thanks, that certainly sounds like the problem but your line of code isn't doing anything? Where do I need to declare that? I've just put it above NSDate *selected = [timePicker date]; and I don't see it doing anything :-(
I do it as soon as I set up the UIDatePicker in my viewDidLoad method of the UIView
James Raybould
Cool that works thanks, it sets my picker at a random value though, do you know how to set it to 0min 0hour?