I\'m experiencing a really strange issue that sounds more like a system bug. I want to format a date using only Hour and Minute information and, if necessary, display AM/PM
Swift 3 & 4:
extension Date {
var localizedStringTime: String {
return DateFormatter.localizedString(from: self, dateStyle: .none, timeStyle: .short)
}
}
You can use the localized string from date function like this...
extension NSDate {
func localizedStringTime()->String {
return NSDateFormatter.localizedStringFromDate(self, dateStyle: NSDateFormatterStyle.NoStyle, timeStyle: NSDateFormatterStyle.ShortStyle)
}
}