NSDateFormatter- stringFromDate not returning AM/PM
Try This
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"hh:mm a"];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
NSString *stringFromTime = [dateFormatter stringFromDate:[NSDate date]];
HH : 24 hour format
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[formatter setLocale:locale];
[formatter setDateFormat:@"HH:mm a"];
output
Today's Time: 16:42 PM
hh : 12 hour format
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[formatter setLocale:locale];
[formatter setDateFormat:@"hh:mm a"];
output
Today's Time: 04:43 PM
Check your device settings for 24 hour time. If it is on, turn it off.
Your code is perfectly fine. I am getting output as shown below : Today's Time: 04:31:58 PM
If you don't want to show seconds use this code :
[formatter setDateFormat:@"hh:mm a"];