I wrote the following code to show a datetime in a particular format:
let formatter = NSDateFormatter()
formatter.dateStyle = NSDateFormatterStyle.LongStyle
formatter.timeStyle = .MediumStyle
formatter.dateFormat = "HH:mm a 'on' MMMM dd, yyyy"
let dateString = formatter.stringFromDate(newDate!)
println(dateString)
Output
12:16 pm on July 17, 2015
I want to show 'pm' as 'PM'(in capitals) and if phone has 24 hours format then AM/PM should not appear. Please help me.
You can set your DateFormatter amSymbol and pmSymbol as follow:
Xcode 8.3 • Swift 3.1