Show time for multiple countries with native time format.
Trying to Display time of Netherland eg: 22.37 uur
With Locale: nl_NL
For Date: 2019-09-17 17:07:00 +0000
I have tried the code below:
let formatter = DateComponentsFormatter()
var calendar = Calendar.gregorianCalendar()
calendar.locale = apiDate.locale // nl_NL
formatter.calendar = calendar
formatter.unitsStyle = .short
formatter.allowedUnits = [.hour, .minute]
formatter.zeroFormattingBehavior = [.dropLeading, .pad]
let dateComponent = calendar.dateComponents([.hour, .minute], from: apiDate.absoluteDate) //apiDate.absoluteDate: Date : 2019-09-17 17:07:00 +0000
print(formatter.string(from: dateComponent) as Any) // prints 22 uur, 37 min
Expected: 22.37 uur
Actual: 22 uur, 37 min