Question

I have the following string "Mar 13, 2013 05:30pm" . I want to convert it into the NSDate object.

I have tried the following way but it is not working.

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMM:dd, YYYY hh:mm:aa"];
date=[dateFormatter dateFromString:dateString];
Was it helpful?

Solution 2

Try this :-

NSString *stringDate = @"Mar 13, 2013 05:30pm";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMM dd, yyyy hh:mmaa"];
NSDate *date=[dateFormatter dateFromString:stringDate];
NSLog(@"Date : %@",date);

Hope it helps you..

OTHER TIPS

NSDateFormatter *dFormate = [[NSDateFormatter alloc] init];
[dFormate setDateFormat:@"MM dd, yyyy hh:mma"];
[dFormate setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];

NSString *dateStr = @"Mar 13, 2013 05:30pm";
NSDate *date = [dFormate dateFromString:dateStr];

NSLog(@"Date : %@", date);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top