您的位置:首页 > 其它

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

2016-02-18 17:35 260 查看
创建datePicker

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

    [timeBaseView addSubview:_datapicg];

    _datapicg.backgroundColor =[UIColor
whiteColor];

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

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

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

    _datapicg.datePickerMode =
UIDatePickerModeDate;

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

    [_datapicg
addTarget:self
action:@selector(dateChange)forControlEvents:UIControlEventValueChanged];

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

获取datePIcker的时间

NSDate *myDate =
_datapicg.date;  

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

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

        NSString *prettyVersion = [dateFormat
stringFromDate:myDate];

        NSLog(@"%@",prettyVersion);

        [self
removeFromSuperview];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: