This question already has an answer here:
How can i convert the following string "October 24,Monday 12:30 AM EST" to NSDateFormat.
i tried this code
NSDateFormatter *dateformat=[[NSDateFormatter alloc]init];
[dateformat setDateFormat:@"MM/DD/YYYY hh:mm a"];
NSDate *datefor=[dateformat dateFromString:appDelegate.appoinmentString];
[dateformat setDateFormat:@"MM-dd-yyyy hh:mm a"];
NSString *dateStr=[dateformat stringFromDate:datefor];
NSDate *datetype=[dateformat dateFromString:dateStr];
Try like below:-
Try this...
Let me know if you have any problem.
Your
dateformat
forOctober 24,Monday 12:30 AM EST
is not correct. The correctdateformat
in your case isMMMM dd,eeee HH:mm a z
.Working Code :
Take a look at Date Format Specifiers.
eeee
- Local day of week spelled out.MMMM
- Month spelled out.dd
- day of month with no leading zeros.HH
- hour of day (24 hour format).mm
- minutes of hour (with leading zero) .z
- timezone (short wall time).