1.根据字符串设置UIDatePicker的初始日期:

UIDatePicker*dataPicker=[[UIDatePickeralloc]init];dataPicker.datePickerMode=UIDatePickerModeDate;dataPicker.minimumDate=[NSDatedateWithTimeIntervalSince1970:0];dataPicker.locale=[[NSLocalealloc]initWithLocaleIdentifier:@"zh_Hans"];dataPicker.maximumDate=[NSDatedate];NSString*str=@"1991-02-16";NSDateFormatter*format=[[NSDateFormatteralloc]init];[formatsetDateFormat:@"yyyy-MM-dd"];NSDate*date=[formatdateFromString:str];dataPicker.date=date;

2.根据UIDatePicker选择中的日期,自定义想要在文本中显示的日期

NSDateFormatter*formate=[[NSDateFormatteralloc]init];[formatesetDateFormat:@"yyyy年-MM月-dd日"];tx.text=[formatestringFromDate:date.date];