MobileGeek
MobileGeek

Reputation: 2512

Add Time to NSDate

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

Answers (2)

wattson12
wattson12

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

Nikunj
Nikunj

Reputation: 987

Check with this If helpful.

MMM,dd yyyy HH:mm

Upvotes: 1

Related Questions