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

Viewed 18302

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];
3 Answers

Swift 5:

You can add handy extension to date formatter:

extension DateFormatter { 
    static let myFormattedDate: DateFormatter = {
         let formatter = DateFormatter()
         formatter.dateFormat = "E MM/dd/yyyy HH:mm a" //enter any format you like.
         formatter.amSymbol = "am" //By default AM/PM symbols are uppercased
         formatter.pmSymbol = "pm"
         return formatter
    }()
}

Then you would use it like this:

DateFormatter.myFormattedDate.string(from: Date()) // Here enter your date and it will return string value formatted to the format you provided with lowercased am/pm symbols.

Checkout NSDateFormatter.com to discover the perfect format.

Related