0

I am using UIDatePickerView, just like we can set the date range using "maximumDate" and "minimumDate", is there any way to set time range in a day like from 9.00 am to 6.00 pm ?

2 Answers2

0

Not really. minimumDate and maximumDate can include a time of day (NSDate is more like a timestamp than a calendar date), but this only has an effect if they are both on the same day because otherwise all (clock) times are possible within the date range.

omz
  • 53,243
  • 5
  • 129
  • 141
0

Actually you should set the time using these two as well. NSDate objects have both date and time components. You should do something like this:

NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];

//set the date using setDate: setMonth: setYear:
[dateComponents setHour:9];    //setHour:18 for maximumDate

NSDate *targetDate = [gregorian dateFromComponents::dateComponents];
[dateComponents release];
[gregorian release];
datepick.minimumDate = targetDate;

If that doesnt help, have a look at these Qs:

UI Datepicker range. iPhone

How to set time on NSDate?

Community
  • 1
  • 1
Bushra Shahid
  • 3,579
  • 1
  • 27
  • 37