如何检索TimezoneDB时间到Swift标签

时间:2019-04-04 05:03:14

标签: json swift timezonedb

我想显示一个倒数计时器使用在线数据库中的时间,标签为Swift 4.0。我不想用手机的时间。

我本来想从Firebase检索时间,但是运气不佳,但后来我找到了timezonedb并取得了一些进步。

我有我的API密钥,想知道如何实现查询。

我已使用API​​密钥将url变量设置为查询,并使用组件提取了信息。

@media only screen and (max-width: 768px) {
  p.progress__info i{margin-right:10px;}
}

希望以hh:mm:ss来获取时间,但是却得到了:

let url = URL(string: "http://api.timezonedb.com/v2.1/get-time-zone?key=YOUR_API_KEY&format=json&by=zone&zone=America/Chicago") // I inserted my API key before but left it blank here

let components = URLComponents(url: url!, resolvingAgainstBaseURL: false)

if let components = components {
    components.host
    components.query
    components.percentEncodedQuery

    if let queryItems = components.queryItems {
        for queryItem in queryItems {
            print("\(queryItem.name): \(queryItem.value)")
        }
    }
}

0 个答案:

没有答案