How to get the IANA/Olsen time zones for a country in Python

Automatic time zone information can be very useful for any business or app, especially when customers are involved. Knowing the correct time to contact someone can spell the difference between satisfaction and disaster. With that in mind I’m going to show you a no-fail method for setting up just such a system.

The process begins with installation of our client:

pip install cloudmersive-validate-api-client

Now continue on by calling address_get_timezone with this set of code here:

from __future__ import print_functionimport timeimport cloudmersive_validate_api_clientfrom import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_validate_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_validate_api_client.AddressApi(cloudmersive_validate_api_client.ApiClient(configuration))input = cloudmersive_validate_api_client.GetTimezonesRequest() # GetTimezonesRequest | Input requesttry:# Gets IANA/Olsen time zones for a countryapi_response = api_instance.address_get_timezone(input)pprint(api_response)except ApiException as e:print("Exception when calling AddressApi->address_get_timezone: %s\n" % e)

Done! Whoever said that easy tasks aren’t worth doing obviously never used an API.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store

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