[英]I want to convert NSString to NSDate but UIPickerView shows current date
I want to convert NSString to NSDate but UIPickerView shows current 我想将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];
any suggestions 有什么建议么
@Ali try this and u will get the string from date @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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.