NSDateFormatter time format depending on Locale

后端 未结 2 1217
既然无缘
既然无缘 2020-12-19 19:03

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

2条回答
  •  爱一瞬间的悲伤
    2020-12-19 19:48

    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)
        }
    }
    

提交回复
热议问题