Q:

UIDatePicker setting minimum and maximum hour

How to set minimum and maximum hour to UIDatePicker ? At all is it possible ?
I know how to set minimum and maximum date:
[datePicker setMinimumDate: today];
[datePicker setMaximumDate: nextMonthDay];
What i want to achieve is that in picker user could select from 8 am to 10 pm every day.
Thanks.

A:

Hope the following code help you.
    - (IBAction)dataPickerValueChanged:(UIDatePicker *)sender {

        NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:NSHourCalendarUnit fromDate:[testDatePicker date]];

        if ([dateComponents hour] > 8 && [dateComponents hour] < 22) {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error!" message:@"This time cant be selected" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles: nil];
            [alert show];
            return;
        }

         lblDate.text = [sender date];

    }

