UIDatePicker日期选取器
1 //定义显示日期的格式 2 NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init]; 3 //NSDateFormatterMediumStyle的显示格式为: Nov 23, 1937” or “3:30:32 PM 4 dateFormat.dateStyle = NSDateFormatterMediumStyle; 5 dateFormat.timeStyle = NSDateFormatterMediumStyle; 6 7 //获取事件选取器的值 8 NSDate *date = self.datePicker.date; 9 //将date按dateFormat的格式转换成NSString对象显示并赋给message 10 NSString *message = [dateFormat stringFromDate:date]; 11 12 UIAlertController *dateAlert = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert]; 13 14 UIAlertAction *dateAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:nil]; 15 16 [dateAlert addAction:dateAction]; 17 18 [self presentViewController:dateAlert animated:YES completion:nil];