UIDatePicker *datePicker = [[UIDatePicker alloc] init]; datePicker.datePickerMode = UIDatePickerModeDate;

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"\n\n\n\n\n\n\n\n\n\n\n\n" message:nil   preferredStyle:UIAlertControllerStyleActionSheet];

[alert.view addSubview:datePicker];

UIAlertAction *ok = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

        NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];

        //实例化一个NSDateFormatter对象

        [dateFormat setDateFormat:@"yyyy-MM-dd"];//设定时间格式

        NSString *dateString = [dateFormat stringFromDate:datePicker.date];

        //求出当天的时间字符串

        NSLog(@"%@",dateString);

    }];

 UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

  }];

[alert addAction:ok];

[alert addAction:cancel];

[self presentViewController:alert animated:YES completion:^{ }];

 

相关文章:

  • 2021-06-12
  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
  • 2021-11-14
  • 2021-12-12
  • 2021-11-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2022-12-23
  • 2021-09-08
相关资源
相似解决方案