Reputation: 1535
I have date in string January-01-2014. I wan to set this date to my date picker. I am doing this to set that date but got error like this:
Assertion failure in -[_UIDatePickerView _setDate:animated:forced:], /SourceCache/UIKit_Sim/UIKit-2903.2/_UIDatePickerView.m:313
2014-01-03 13:17:22.095 GratZeez[1469:a0b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: date'
My code is:
df = [[NSDateFormatter alloc] init];
df.dateStyle=NSDateFormatterMediumStyle;
datePicker.date=[df dateFromString:[tempArray objectAtIndex:2]];
Upvotes: 0
Views: 207
Reputation: 23301
check this and change dateformat if causing anything change as your time zone too
NSDateFormatter *formatDate = [[NSDateFormatter alloc] init];
[formatDate setDateFormat:@"dd-MM-yyyy HH:mm:ss"];
NSTimeZone *zoneTime=[NSTimeZone defaultTimeZone];
[formate setTimeZone:zoneTime];
NSDate *date = [formate dateFromString:yourDateArray];
NSLog(@"Output date :%@",date);
[yourDatePicker setDate:date];
Upvotes: 0
Reputation: 1179
Try below code your app cannot get crashed.
df = [[NSDateFormatter alloc] init];
df.dateStyle=NSDateFormatterMediumStyle;
[df setDateFormat:@"MMMM-dd-yyyy"];
datePicker.date=[df dateFromString:[tempArray objectAtIndex:2]];
Upvotes: 2