斯威夫特4
获取当前用户时区:
let currentTimeZone = TimeZone.current
获取所有时区:
let timeZoneIdentifiers = TimeZone.knownTimeZoneIdentifiers
使用标识符创建时区:
let berlin = TimeZone(identifier: "Europe/Berlin")!
获取时区的城市名称:
let cityName = berlin.identifier.split(separator: "/")[1]
获取所有城市名称:
var allCities: [String] = []
for identifier in timeZoneIdentifiers {
if let cityName = identifier.split(separator: "/").last {
allCities.append("\(cityName)")
}
}