zoukankan      html  css  js  c++  java
  • 日期选择器

      birthDate = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,500/2,self.view.frame.size.width, 88/2)];
                birthDate.datePickerMode = UIDatePickerModeDate;// 设置只显示日期
                [birthDate addTarget:self action:@selector(setBirthDate:) forControlEvents:UIControlEventValueChanged];
                [self.view addSubview:birthDate];
                
                //设置toolbar
                pickerToolbar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 470/2, self.view.frame.size.width, 30)];
                [pickerToolbar setBackgroundColor:[UIColor clearColor]];
                UIBarButtonItem* sureItem=[[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(hiddenPicker:)];
                sureItem.tag = 10;
                UIBarButtonItem* cancelItem=[[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(hiddenPicker:)];
                UIBarButtonItem* flexItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
                flexItem.tag = 11;
    //            pickerToolbar.hidden=YES;
                pickerToolbar.items=@[sureItem,flexItem,cancelItem];
    
                [self.view addSubview:pickerToolbar];
    
    /*
     *@brief 选择出生日期方法
     **
     */
    - (void)setBirthDate:(id)sender
    {
        NSLog(@"设置出生日期");
        // 获取用户通过UIDatePicker设置的日期和时间
        NSDate *selected = [birthDate date];
        // 创建一个日期格式器
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        // 为日期格式器设置格式字符串
        [dateFormatter setDateFormat:@"MM月dd日"];
        // 使用日期格式器格式化日期、时间
        destDateString = [dateFormatter stringFromDate:selected];
        NSLog(@"string === %@",destDateString);
        [personMessageArr replaceObjectAtIndex:5 withObject:destDateString];
        NSLog(@"%@",personMessageArr);
        /// 调用修改日期接口
        
        
    
    }
    
  • 相关阅读:
    javascript时间戳和日期字符串相互转换
    jquery两稳定版本比较~~
    原生的强大DOM选择器querySelector
    分享一个自定义的 console 类,让你不再纠结JS中的调试代码的兼容
    基于Mesos运行Spark
    chrome插件 postman 可以调用restful服务
    cassandra优秀博客集
    Cassandra监控
    Cassandra
    SecureCRT中文显示乱码的解决方法
  • 原文地址:https://www.cnblogs.com/angongIT/p/4536696.html
Copyright © 2011-2022 走看看