views:

160

answers:

2

All,

This seems like such a simple thing, but I cannot find* the right method to create a UIDatePicker, in time mode, and have it initialized to a specific time. I don't want date -- just time (think alarm clock). I have created a NSDate object:

NSDate * date = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate: (NSTimeInterval) delta];
pickerView = [[UIDatePicker alloc] init];  // which should be 'now' right?
pickerView.datePickerMode = UIDatePickerModeTime;  // which creates just the clock
[pickerView setDate:date];

and in the first line, the interval (delta) is zero. It displays 7:00PM.

This has gotta be so simple that I'm missing it, but I can't find the right way -- anyone?

Thank you in advance!

:bp:

*yes, I have looked, but apparently not in the correct places :(

A: 

Take the time zone into account. You will get 0AM only if you are at UTC.

dkk
Thank you for the response!I did set the time zone to both the default and the real time zone. Since this is in the iPhone simulator, the location believes itself to be California. The *real* question, I suppose, is if I want to initialize the DatePicker time to: 7:14 AM -- how do I? All I want to get out of it is the value after it is changed, e.g., 7:20 AM. Is this even the right widget to use?
Billy Pilgrim
to set the time [pickerView setDate:date]; is correct, you just need to set a date with the right time. To get the date that is selected just do [pickerView date] and get the time from the date.
dkk
A: 

Thank you dkk -- I appreciate your help. The real answer was to not use a DatePicker, but to use a PickerView (w/o the date). That made things simpler and do-able. Thanks again.

Billy Pilgrim