获取iOS时区中的城市和国家/地区列表
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取iOS时区中的城市和国家/地区列表相关的知识,希望对你有一定的参考价值。
我希望能够访问“设置”>“常规”>“日期和时间”中显示的用户友好时区列表。有人可以帮助提供此代码吗?
斯威夫特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)")
}
}
要获得完整列表:
let knownTimeZoneIdentifiers = TimeZone.knownTimeZoneIdentifiers
for tz in TimeZone.knownTimeZoneIdentifiers {
let timeZone = TimeZone(identifier: tz)
if let abbreviation = timeZone?.abbreviation(), let seconds = timeZone?.secondsFromGMT() {
print ("timeZone: (tz)
abbreviation: (abbreviation)
secondsFromGMT: (seconds)
")
}
}
目前显示此列表:
TZ:非洲/阿比让Abbr:GMT SecondsFromGMT:0
TZ:Africa / Accra Abbr:GMT SecondsFromGMT:0
TZ:Africa / Addis_Ababa Abbr:GMT + 3 SecondsFromGMT:10800
TZ:Africa / Algiers Abbr:CET SecondsFromGMT:3600
TZ:Africa / Romance Abbr:SecondsFromGMT GMT + 3:10800
TZ:Africa / Bamako Abbr:GMT SecondsFromGMT:0
TZ:Africa / Bangui Abbr:GMT + 1 SecondsFromGMT:3600
TZ:Africa / Banjul Abbr:GMT SecondsFromGMT:0
TZ:Africa / Bissau Abbr:GMT SecondsFromGMT:0
TZ:Africa / Blantyre Abbr:GMT + 2 SecondsFromGMT:7200
TZ:Africa / Brazzaville Abbr:GMT + 1 SecondsFromGMT:3600
TZ:Africa / Bujumbura Abbr:GMT + 2 SecondsFromGMT:7200
TZ:Africa / Cairo Abbr:EET SecondsFromGMT:7200
TZ:Africa / Casablanca Abbr:WET SecondsFromGMT:0
TZ:Africa / Ceuta Abbr:CET SecondsFromGMT:3600
TZ:Africa / Conakry Abbr:GMT SecondsFromGMT:0
TZ:Africa / Dakar Abbr:GMT SecondsFromGMT:0
TZ:Africa / Dar_es_Salaam Abbr:GMT + 3 SecondsFromGMT:10800
TZ:Africa / Djibouti Abbr:GMT + 3 SecondsFromGMT:10800
TZ:Africa / Douala Abbr:GMT + 1 SecondsFromGMT:3600
TZ:Africa / El_Aaiun Abbr:WET SecondsFromGMT:0
TZ:Africa / Freetown Abbr:GMT SecondsFromGMT:0
TZ:Africa / Gaborone Abbr:GMT + 2 SecondsFromGMT:7200
TZ:Africa / Harare Abbr:GMT + 2 SecondsFromGMT:7200
TZ:Africa / Johannesburg Abbr:GMT + 2 SecondsFromGMT:7200
TZ:Africa / Juba Abbr:GMT + 3 SecondsFromGMT:10800
TZ:Africa / Kampala Abbr:GMT + 3 SecondsFromGMT:10800
TZ:Africa / Khartoum Abbr:GMT + 2 SecondsFromGMT:7200
TZ:Africa / Kigali Abbr:GMT + 2 SecondsFromGMT:7200
TZ:Africa / Kinshasa Abbr:GMT + 1 SecondsFromGMT:3600
TZ:Africa / Lagos Abbr:GMT + 1 SecondsFromGMT:3600
TZ:Africa / Libreville Abbr:GMT + 1 SecondsFromGMT:3600
TZ:Africa / Lome Abbr:GMT SecondsFromGMT:0
TZ:Africa / Luanda Abbr:GMT + 1 SecondsFromGMT:3600
TZ:Africa / Lubumbashi Abbr:GMT + 2 SecondsFromGMT:7200
TZ:Africa / Lusaka Abbr:GMT + 2 SecondsFromGMT:7200
TZ:Africa / Malabo Abbr:GMT + 1 SecondsFromGMT:3600
TZ:Africa / Maputo Abbr:GMT + 2 SecondsFromGMT:7200
TZ:Africa / Maseru Abbr:GMT + 2 SecondsFromGMT:7200
TZ:Africa / Mbabane Abbr:GMT + 2 SecondsFromGMT:7200
TZ:Africa / Mogadishu Abbr:GMT + 3 SecondsFromGMT:10800
TZ:非洲/蒙罗维亚Abbr:GMT SecondsFromGMT:0
TZ:Africa / Nairobi Abbr:GMT + 3 SecondsFromGMT:10800
TZ:Africa / Ndjamena Abbr:GMT + 1 SecondsFromGMT:3600
TZ:Africa / Niamey Abbr:GMT + 1 SecondsFromGMT:3600
TZ:Africa / Nouakchott Abbr:GMT SecondsFromGMT:0
TZ:Africa / Ouagadougou Abbr:GMT SecondsFromGMT:0
TZ:Africa / Porto-Novo Abbr:GMT + 1 SecondsFromGMT:3600
TZ:Africa / Sao_Tome Abbr:GMT SecondsFromGMT:0
TZ:Africa / Tripoli Abbr:EET SecondsFromGMT:7200
TZ:Africa / Tunis Abbr:CET SecondsFromGMT:3600
TZ:Africa / Windhoek Abbr:GMT + 2 SecondsFromGMT:7200
TZ:America / Adak Abbr:GMT-10 SecondsFromGMT:-36000
TZ:America / Anchorage Abbr:GMT-9 SecondsFromGMT:-32400
TZ:America / Anguilla Abbr:GMT-4 SecondsFromGMT:-14400
TZ:America / Antigua Abbr:GMT-4 SecondsFromGMT:-14400
TZ:America / Araguaina Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Argentina / Buenos_Aires Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Argentina / Catamarca Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Argentina / Cordoba Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Argentina / Jujuy Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Argentina / La_Rioja Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Argentina / Mendoza Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Argentina / Rio_Gallegos Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Argentina / Skip Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Argentina / San_Juan Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Argentina / San_Luis Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Argentina / Tucuman Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Argentina / Ushuaia Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Aruba Abbr:GMT-4 SecondsFromGMT:-14400
TZ:America / Asuncion Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Atikokan Abbr:GMT-5 SecondsFromGMT:-18000
TZ:America / Bahia Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Bahia_Banderas Abbr:GMT-6 SecondsFromGMT:-21600
TZ:America / Barbados Abbr:GMT-4 SecondsFromGMT:-14400
TZ:America / Belem Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Belize Abbr:GMT-6 SecondsFromGMT:-21600
TZ:America / Blanc-Sablon Abbr:GMT-4 SecondsFromGMT:-14400
TZ:America / Boa_Vista Abbr:GMT-4 SecondsFromGMT:-14400
TZ:America / Bogota Abbr:GMT-5 SecondsFromGMT:-18000
TZ:America / Boise Abbr:GMT-7 SecondsFromGMT:-25200
TZ:America / Cambridge_Bay Abbr:GMT-7 SecondsFromGMT:-25200
TZ:America / Campo_Grande Abbr:GMT-4 SecondsFromGMT:-14400
TZ:America / Cancun Abbr:GMT-5 SecondsFromGMT:-18000
TZ:America / Caracas Abbr:GMT-4 SecondsFromGMT:-14400
TZ:America / Cayenne Abbr:GMT-3 SecondsFromGMT:-10800
TZ:America / Cayman Abbr:GMT-5 SecondsFromGMT:-18000
TZ:America / Chicago Abbr:GMT-6 SecondsFromGMT:-21600
TZ:America / Chihuahua Abbr:GMT-7 SecondsFromGMT:-25200
TZ:America / Costa_Rica Abbr:GMT-6 SecondsFromGMT:-21600
TZ:America / Creston Abbr:GMT-7 SecondsFromGMT:-25200
TZ:America / Cuiaba Abbr:GMT-4 SecondsFromGMT:-14400
TZ:America / Curacao Abbr:GMT-4 SecondsFromGMT:-14400
TZ:America / Danmarkshavn Abbr:GMT SecondsFromGMT:0
TZ:America / Dawson Abbr:GMT-8 SecondsFromGMT:-28800
TZ:America / Dawson_Creek Abbr:GMT-7 SecondsFromGMT:-25200
TZ:America / Denver Abbr:GMT-7 SecondsFromGMT:-25200
TZ:America / Detroit Abbr:GMT-5 SecondsFromGMT:-18000
TZ:America / Dominica Abbr:GMT-4 SecondsFromGMT:-14400
TZ:America / Edmonton Abbr:GMT-7 SecondsFromGMT:-25200
TZ:America / Eirunepe Abbr:GMT-5 SecondsFromGMT:-18000
TZ:America / El_Salvador Abbr:GMT-6 SecondsFromGMT:-21600
TZ:America / Fort_Nelson Abbr:GMT-7 SecondsFromGMT:-25200
TZ:America / Fortaleza Abbr:GMT-3 SecondsFromG
以上是关于获取iOS时区中的城市和国家/地区列表的主要内容,如果未能解决你的问题,请参考以下文章
无法从 Swift 中的 Facebook iOS SDK 捕获城市和国家/地区值