Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setTimeStyle AM/PM to lowercase using the iPhone SDK

How can I set the AM / PM time style to lowercase? I'm using the following code and according to Apple's documentation this should returned these values as lowercase but it doesn't.

[_detailsTimeFormatter setTimeStyle:NSDateFormatterShortStyle];
like image 333
Jim Avatar asked Nov 27 '09 15:11

Jim


2 Answers

You can change the AM and PM symbols on an NSDateFormatter as follows:

[dateFormatter setAMSymbol:@"am"];
[dateFormatter setPMSymbol:@"pm"];

or in Swift:

formatter.amSymbol = "am"
formatter.pmSymbol = "pm"
like image 120
michaelslater Avatar answered Sep 24 '22 21:09

michaelslater


I am not sure why Apple's examples show the AM / PM in lower case, but it is easy to make the date string lower case:

NSDateFormatter *detailsTimeFormatter = [[NSDateFormatter alloc] init];
[detailsTimeFormatter setTimeStyle:NSDateFormatterShortStyle];
NSLog(@"%@",[[detailsTimeFormatter stringFromDate:[NSDate date]] lowercaseString]);
like image 36
gerry3 Avatar answered Sep 25 '22 21:09

gerry3