2011-12-23 53 views

回答

2

使用minimumDate和maximumDate性能

NSDateComponents* dc = [[NSDateComponents alloc] init]; 
[dc setYear:2011]; 
... 
NSCalendar* c = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 
NSDate* date = [c dateFromComponents:dc]; 
dp.minimumDate = date; 
.... 
datePicker.maximumDate = d; 
0

在你看来,你从故事板创建的UIDatePicker。如果选择任何日期该日期将显示在文本框是这样的:

NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; 
[formatter setDateFormat:@"HH:mm"]; 
//NSDate *date = [[NSDate alloc]init]; 
NSDate *date = [sender date]; 
NSString *formattedDateStringTime = [formatter stringFromDate:date]; 
[self setSelectedDate:formattedDateStringTime]; 
NSLog(@"value: %@",formattedDateStringTime); 
[formatter release]; 

//if (currentTextField.tag==101) { 
currentTextField.text=formattedDateStringTime; 

试试这个当前的日期将显示在文本框和这样的你需要得到结束时间。最后再给文本提交的文本是:

currentTextField.text=[NSString StringWithFormat:"%@ to %@",formattedDateStringTime,formattedDateEndTime]; 

试试这个,我认为你可以得到答案。

相关问题