使用本地时间格式显示多个国家/地区的时间。
尝试显示荷兰时间,例如:22.37 uur
使用语言环境: nl_NL
日期::2019-09-17 17:07:00 +0000
我已经尝试过以下代码:
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
预期: 22.37 uur
实际: 22 uur, 37 min