get AM / PM from users set time on iOS

cocoa-touch, ios, iphone, xcode

Solution

Here you go. This is the date with am/pm formatting.

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"hh:mm:ss a"];
NSLog(@"Today's Date and Time: %@", [formatter stringFromDate:[NSDate date]]);
[formatter release];

Problem

I am wondering if there is a way that you can get am/pm from the users set time on iOS. I am currently using this method to get time: ``` NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"HH"]; hours.text = [formatter stringFromDate:[NSDate date]]; [formatter setDateFormat:@"m"]; minutes.text = [formatter stringFromDate:[NSDate date]]; if ([minutes.text intValue] < 10) { minutes.text = [NSString stringWithFormat:@"0%@",[formatter stringFromDate:[NSDate date]]]; } [formatter release]; ``` I know I am using HH to get the hours and for the 12 hour format I have to use "hh" bu this does not solve the problem, I need to retrieve the AM/PM. Hopefully someone can help!

Original source