NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
NSDate *date1 =[[NSDate alloc] init];
date1 = [dateFormat dateFromString:@"11-nov-2013"];
NSLog(@"date is %@",date1); // it returns null
self.datePicker.date = date1;
[dateFormat release];
答案 0 :(得分:1)
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"dd-MMM-yyyy"];
NSDate *myDate = [formatter dateFromString:@"11-nov-2013"];
NSLog(@"date is %@",myDate);
答案 1 :(得分:0)
将日期格式设为
[dateFormat setDateFormat:@"dd-MM-yyyy"];
答案 2 :(得分:0)
您还需要设置日期格式:
[dateFormat setDateFormat:@"dd-MM-yyyy"];