How to Get Time Zones for a Country in Swift

2 min readMay 18, 2021


For the past 30 years, online capabilities have steadily grown in quality and number. As a direct result of this growth, international business has also seen a tremendous increase. To ensure your out-of-country customers and partners are receiving correct information pertaining to their location, it can be helpful to incorporate a time zone conversion tool into your website or application. The following API can be used in Swift to automatically get the Olson time zones for a specific country, allowing you to save the time it would take to build it out manually.

Now to perform the operation, all you’ll need are the country name or ISO code, as well as your API key to plug into the below code:

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
var semaphore = DispatchSemaphore (value: 0)let parameters = "{\n \"CountryCodeOrName\": \"<string>\"\n}"
let postData = .utf8)
var request = URLRequest(url: URL(string: "")!,timeoutInterval: Double.infinity)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("YOUR-API-KEY-HERE", forHTTPHeaderField: "Apikey")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
print(String(data: data, encoding: .utf8)!)

Your prompt response will indicate the country name, time zones, and current time along with the two-letter ISO code, two-letter FIPS code, and three-letter code.




There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.