时间选择器机获取上边时间

来源:互联网 发布:国家顶级域名汇总 编辑:程序博客网 时间:2024/03/29 08:11


创建datePicker

_datapicg =[[UIDatePickeralloc] initWithFrame:CGRectMake(0,0, timeBaseView.bounds.size.width, timeBaseView.bounds.size.height-30)];

    [timeBaseView addSubview:_datapicg];

    _datapicg.backgroundColor =[UIColorwhiteColor];

    // 设置区域为中国简体中文

    _datapicg.locale = [[NSLocalealloc] initWithLocaleIdentifier:@"zh_CN"];

    // 设置picker的显示模式:只显示日期

    _datapicg.datePickerMode =UIDatePickerModeDate;

    //    10.3UIDatePicker需要监听值的改变

    [_datapicgaddTarget:selfaction:@selector(dateChange)forControlEvents:UIControlEventValueChanged];


 dateChange  这个方法是滑动时间的滚动条的事后调用的停止之后就开始调用这个方法;

获取datePIcker的时间

NSDate *myDate =_datapicg.date;  

        NSDateFormatter *dateFormat = [[NSDateFormatteralloc] init];

        [dateFormat setDateFormat:@"YYYY.MM.DD"];

        NSString *prettyVersion = [dateFormat stringFromDate:myDate];

        NSLog(@"%@",prettyVersion);

        [selfremoveFromSuperview];



0 0
原创粉丝点击