如何从NSString
UIDatePickerView
传递时间
答案 0 :(得分:4)
-(void)viewDidLoad {
[super viewDidLoad];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
NSString * date = @"2010-12-10";
[dateFormat setDateFormat:@"yyyy'-'MM'-'dd"];
NSDate *anyDate = [dateFormat dateFromString:date];
[datePicker setDate:anyDate];
[dateFormat release];
}
没有测试它,但应该工作..或者指出你正确的方向
编辑时间:
-(void)viewDidLoad {
[super viewDidLoad];
NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
NSString * time = @"08:00-am";
[timeFormat setTimeFormat:@"hh':'mm'-'tt"];
NSDate *anyTime = [timeFormat dateFromString:time];
[datePicker setTime:anyTime];
[timeFormat release];
}