My original date format is : 2014-03-14T10:35:24.537
So I first separate the time and date with componentsSeparatedByString, then I save the second half (the time part) to NSString time, while eliminating the microseconds. to the format 10:35. I'm trying to get it to add PM/AM but setDateFormat:@"hh:mm a" is not doing it. What am I doing wrong?
NSArray *components = [datestr componentsSeparatedByString:@"T"];
NSString *time = components[1];
time = [time substringWithRange:NSMakeRange(0, 5)];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"hh:mm a"];
NSDate *timeFromString = [formatter dateFromString:time];
NSLog(@"%@", timeFromString);
When I log timeFromString, I get a null.
EDIT: I changed the formatter above to [formatter setDateFormat:@"hh:mm"]; and now the timeFromString logs as: 2000-01-01 18:35:00 +0000 when data coming in is 2014-03-14T10:35:28.42