Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取城市&;iOS时区中的国家/地区列表_Ios_Swift_Timezone - Fatal编程技术网

获取城市&;iOS时区中的国家/地区列表

获取城市&;iOS时区中的国家/地区列表,ios,swift,timezone,Ios,Swift,Timezone,我想访问显示在“设置”>“常规”>“日期和时间”中的用户友好时区列表。有人能帮忙提供这方面的代码吗 试试这个: let timezone = TimeZone.current.identifier 这将返回“美国/圣保罗” 抱歉,这将获取所有列表: let array = TimeZone.knownTimeZoneIdentifiers Swift 4 获取当前用户时区: let currentTimeZone = TimeZone.current let cityName = berl

我想访问显示在“设置”>“常规”>“日期和时间”中的用户友好时区列表。有人能帮忙提供这方面的代码吗

试试这个:

let timezone = TimeZone.current.identifier
这将返回“美国/圣保罗”

抱歉,这将获取所有列表:

let array = TimeZone.knownTimeZoneIdentifiers

Swift 4

获取当前用户时区:

let currentTimeZone = TimeZone.current
let cityName = berlin.identifier.split(separator: "/").last!
获取所有时区:

let timeZoneIdentifiers = TimeZone.knownTimeZoneIdentifiers
使用标识符创建时区:

let berlin = TimeZone(identifier: "Europe/Berlin")!
获取时区的城市名称:

let currentTimeZone = TimeZone.current
let cityName = berlin.identifier.split(separator: "/").last!
获取所有城市名称:

    let allCities = timeZoneIdentifiers.compactMap { identifier in
        return identifier.split(separator: "/").last
    }
要获取完整列表,请执行以下操作:

    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) \nabbreviation: \(abbreviation)\nsecondsFromGMT: \(seconds)\n")
        }
    }
当前显示此列表:

TZ:非洲/阿比让缩写:GMT秒自GMT:0

TZ:非洲/阿克拉缩写:GMT秒自GMT:0

TZ:非洲/亚的斯亚贝巴缩写:格林尼治标准时间+3秒格林尼治标准时间:10800

TZ:非洲/阿尔及尔缩写:CET秒自GMT:3600

TZ:非洲/阿斯马拉缩写:格林尼治标准时间+3秒格林尼治标准时间:10800

TZ:非洲/巴马科缩写:GMT秒自GMT:0

TZ:非洲/班吉缩写:格林尼治标准时间+1秒格林尼治标准时间:3600

TZ:非洲/班珠尔缩写:GMT秒自GMT:0

TZ:非洲/比绍缩写:格林尼治时间秒格林尼治时间:0

TZ:非洲/布兰太尔缩写:格林尼治标准时间+2秒格林尼治标准时间:7200

TZ:非洲/布拉柴维尔缩写:格林尼治标准时间+1秒格林尼治标准时间:3600

TZ:非洲/布琼布拉缩写:格林尼治标准时间+2秒格林尼治标准时间:7200

TZ:非洲/开罗缩写:EET Seconds格林尼治标准时间:7200

TZ:非洲/卡萨布兰卡缩写:湿秒格林尼治标准时间:0

TZ:Africa/Ceuta缩写:CET Seconds自GMT:3600起

TZ:非洲/科纳克里缩写:GMT秒自GMT:0

TZ:非洲/达喀尔缩写:GMT秒自GMT:0

TZ:非洲/达累斯萨拉姆缩写:格林尼治标准时间+3秒格林尼治标准时间:10800

TZ:非洲/吉布提缩写:格林尼治标准时间+3秒格林尼治标准时间:10800

TZ:非洲/杜阿拉缩写:格林尼治标准时间+1秒格林尼治标准时间:3600

TZ:Africa/El_Aiun缩写:湿秒自GMT:0

TZ:非洲/弗里敦缩写:GMT秒自GMT:0

TZ:非洲/哈博罗内缩写:格林尼治标准时间+2秒格林尼治标准时间:7200

TZ:非洲/哈拉雷缩写:格林尼治标准时间+2秒格林尼治标准时间:7200

TZ:非洲/约翰内斯堡缩写:格林尼治标准时间+2秒格林尼治标准时间:7200

TZ:非洲/朱巴缩写:格林尼治标准时间+3秒格林尼治标准时间:10800

TZ:非洲/坎帕拉缩写:格林尼治标准时间+3秒格林尼治标准时间:10800

TZ:非洲/喀土穆缩写:格林尼治标准时间+2秒格林尼治标准时间:7200

TZ:非洲/基加利缩写:格林尼治标准时间+2秒格林尼治标准时间:7200

TZ:非洲/金沙萨缩写:格林尼治标准时间+1秒格林尼治标准时间:3600

TZ:非洲/拉各斯缩写:格林尼治标准时间+1秒格林尼治标准时间:3600

TZ:非洲/利伯维尔缩写:格林尼治标准时间+1秒格林尼治标准时间:3600

TZ:非洲/洛美缩写:GMT秒自GMT:0

TZ:非洲/罗安达缩写:格林尼治标准时间+1秒格林尼治标准时间:3600

TZ:Africa/Lubumbashi缩写:格林尼治标准时间+2秒格林尼治标准时间:7200

TZ:非洲/卢萨卡缩写:格林尼治标准时间+2秒格林尼治标准时间:7200

TZ:非洲/马拉博缩写:格林尼治标准时间+1秒格林尼治标准时间:3600

TZ:非洲/马普托缩写:格林尼治标准时间+2秒格林尼治标准时间:7200

TZ:Africa/Maseru缩写:格林尼治标准时间+2秒格林尼治标准时间:7200

TZ:Africa/Mbabane缩写:格林尼治标准时间+2秒格林尼治标准时间:7200

TZ:非洲/摩加迪沙缩写:格林尼治标准时间+3秒格林尼治标准时间:10800

TZ:非洲/蒙罗维亚缩写:GMT秒自GMT:0

TZ:非洲/内罗毕缩写:格林尼治标准时间+3秒格林尼治标准时间:10800

TZ:Africa/Ndjamena缩写:格林尼治标准时间+1秒格林尼治标准时间:3600

TZ:非洲/尼亚美缩写:格林尼治标准时间+1秒格林尼治标准时间:3600

TZ:非洲/努瓦克肖特缩写:GMT秒自GMT:0

TZ:非洲/瓦加杜古缩写:GMT秒自GMT:0

TZ:Africa/Porto Novo缩写:格林尼治标准时间+1秒格林尼治标准时间:3600

TZ:非洲/圣多美缩写:GMT秒自GMT:0

TZ:非洲/的黎波里缩写:EET Seconds格林尼治标准时间:7200

TZ:非洲/突尼斯缩写:CET秒格林尼治标准时间:3600

TZ:非洲/温得和克缩写:格林尼治标准时间+2秒格林尼治标准时间:7200

TZ:America/Adak缩写:格林尼治标准时间-10秒格林尼治标准时间:-36000

TZ:美国/安克雷奇缩写:GMT-9秒自GMT:-32400

TZ:美国/安圭拉缩写:GMT-4秒自GMT:-14400

TZ:美国/安提瓜缩写:GMT-4秒自GMT:-14400

TZ:美洲/阿拉瓜那缩写:格林尼治标准时间-3秒格林尼治标准时间:-10800

TZ:美国/阿根廷/布宜诺斯艾利斯缩写:格林尼治标准时间-3秒格林尼治标准时间:-10800

TZ:美国/阿根廷/卡塔马卡缩写:GMT-3秒自GMT:-10800

TZ:美国/阿根廷/科尔多瓦缩写:GMT-3秒自GMT:-10800

TZ:美国/阿根廷/朱朱伊缩写:格林尼治标准时间-3秒格林尼治标准时间:-10800

TZ:美国/阿根廷/拉乌里奥哈缩写:GMT-3秒自GMT:-10800

TZ:美国/阿根廷/门多萨缩写:GMT-3秒自GMT:-10800

TZ:美国/阿根廷/里约热内卢加列戈斯缩写:格林尼治标准时间-3秒格林尼治标准时间:-10800

TZ:美国/阿根廷/萨尔塔缩写:GMT-3秒自GMT:-10800

TZ:美国/阿根廷/圣胡安缩写:GMT-3秒自GMT:-10800

TZ:美国/阿根廷/圣路易斯缩写:GMT-3秒自GMT:-10800

TZ:美国/阿根廷/图库曼缩写:GMT-3秒自GMT:-10800

TZ:美国/阿根廷/乌斯怀亚缩写:GMT-3秒自GMT:-10800

TZ:美国/阿鲁巴缩写:GMT-4秒自GMT:-14400

TZ:美国/亚松森缩写:GMT-3秒自GMT:-10800

TZ:America/Atikokan缩写:GMT-5秒自GMT:-18000

TZ:America/Bahia缩写:GMT-3秒自GMT:-10800

TZ:America/Bahia_Banderas缩写:GMT-6秒自GMT:-21600

TZ:美国/巴巴多斯缩写:GMT-4秒自GMT:-14400

TZ:America/Belem缩写:GMT-3秒自GMT:-10800

TZ:美国/伯利兹缩写:GMT-6秒自GMT:-21600

TZ:America/Blanc Sablon缩写:GMT-4秒自GMT:-14400

TZ:America/Boa_Vista缩写:GMT-4秒自GMT:-14400

TZ:美国/波哥大缩写:GMT-5秒自GMT:-18000

TZ:America/Boise缩写:GMT-7