• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
hiei03301
博客园    首页    新随笔    联系   管理    订阅  订阅

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]; 

 

posted @ 2016-08-09 15:10  hiei03301  阅读(246)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3