1.根据字符串设置UIDatePicker的初始日期:
UIDatePicker * dataPicker = [[UIDatePicker alloc]init]; dataPicker.datePickerMode = UIDatePickerModeDate; dataPicker.minimumDate = [NSDate dateWithTimeIntervalSince1970:0]; dataPicker.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_Hans"]; dataPicker.maximumDate = [NSDate date]; NSString * str = @"1991-02-16"; NSDateFormatter * format = [[NSDateFormatter alloc]init]; [format setDateFormat:@"yyyy-MM-dd"]; NSDate * date = [format dateFromString:str]; dataPicker.date = date;
2.根据UIDatePicker选择中的日期,自定义想要在文本中显示的日期
NSDateFormatter * formate = [[NSDateFormatter alloc]init]; [formate setDateFormat:@"yyyy年-MM月-dd日"]; tx.text = [formate stringFromDate:date.date];
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。