我想将NSString转换为NSDate,但UIPickerView显示当前的
datedatePicker=[[UIDatePicker alloc]init];
datePicker.userInteractionEnabled=YES;
datePicker.minuteInterval=5;
NSLog(@"Date");
////////
NSString *curDate=alarmData.date;
//Jan 14, 2011 11:37
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"MMM dd, yyyy HH:mm"];
//Optionally for time zone converstions
[format setTimeZone:[NSTimeZone timeZoneWithName:nil]];
NSDate *da = [format dateFromString:curDate];
[datePicker setDate:da animated:YES];
任何建议
答案 0 :(得分:4)
@Ali尝试这个,你将从日期
获得字符串NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM dd, yyyy HH:mm"];
//conversion of NSString to NSDate
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [formatter dateFromString:curDate];
[formatter release];