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

Today is all about speed, namely the speedy setup of time zones by country in PHP. Forget all that slow-paced coding, we are going straight for the money. That means busting out an API to tackle this problem.

Use Composer to install our API client using this command:

composer require cloudmersive/cloudmersive_validate_api_client

Now for our function:

<?phprequire_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Apikey', 'Bearer');$apiInstance = new Swagger\Client\Api\AddressApi(// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.// This is optional, `GuzzleHttp\Client` will be used as GuzzleHttp\Client(),$config);$input = new \Swagger\Client\Model\GetTimezonesRequest(); // \Swagger\Client\Model\GetTimezonesRequest | Input requesttry {$result = $apiInstance->addressGetTimezone($input);print_r($result);} catch (Exception $e) {echo 'Exception when calling AddressApi->addressGetTimezone: ', $e->getMessage(), PHP_EOL;}?>

Enter your country name and voila! The time zone! Yup, it’s just that easy. From here, check out our other APIs within the validate client for such functionality as name, address, and email validation.

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