iPhone中的UIDatePicker视图

时间:2010-12-10 15:10:44

标签: iphone objective-c uidatepicker

如何从NSString

中的UIDatePickerView传递时间

1 个答案:

答案 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];
}