Reputation: 2512
I have two UIDatePicker in a view. One for getting Date and Another for the Time. I am getting the Time properly. Now I need to Append Time with the Date for setting firedate of Local Notification. On appending both, I am getting null in NSDate
NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"MMM,dd YYYY HH:mm a"];
[dateFormat setLocale:[NSLocale currentLocale]];
[dateFormat setTimeZone:[NSTimeZone systemTimeZone]];
NSDate *tempDate = [dateFormat dateFromString:[NSString stringWithFormat:@"%@ %@",txtDate.text,txttime.text]];
localNotif.fireDate = tempDate;
While txtDate.text is Aug,06 2012 and txtTime.text is 7:04 pm. I am getting tempDate as null. I have tried various date format for this. Please suggest.
Upvotes: 1
Views: 152
Reputation: 11174
YYYY-MM-dd HH:mm:ss
doesnt match
Aug,06 2012 7:04 pm
it should be MMM,dd YYYY HH:mm a
also since you're pm is in lower case, you may need to set the AMSymbol
and PMSymbol
properties of the date formatter
Upvotes: 2