hello can any one point me to hoe make a date format that looks like this: 13th June 2007. Notice the day has the word "th". I want to add that in my format. Thanks!
Updated for Swift 3
You can do something like this which is locale safe.
let calendar = Calendar.current
let date = Date()
let dateComponents = calendar.component(.day, from: date)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .ordinal
let day = numberFormatter.string(from: dateComponents as NSNumber)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM yyyy"
let dateString = "\(day!) \(dateFormatter.string(from: date))"
print(dateString)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With