How to Get IANA/Olsen Time Zones for a Country in PHP

Cloudmersive
1 min readApr 19, 2023

--

Using the free API solution provided in this article, you can easily get time zones for an input country (country name OR country code) in a single request. For example, the input “France” will return the following response:

{
"Successful": true,
"CountryFullName": "France",
"ISOTwoLetterCode": "FR",
"FIPSTwoLetterCode": "FR",
"ThreeLetterCode": "FRA",
"Timezones": [
{
"Name": "Romance Standard Time",
"BaseUTCOffset": "01:00:00",
"Now": "2023-04-19T16:42:47.4053979"
}
]
}

To take advantage of this API, you can start by installing the client SDK. Run the following command to do so:

composer require cloudmersive/cloudmersive_validate_api_client

After that, copy the below code examples to structure your API call:

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');



$apiInstance = new Swagger\Client\Api\AddressApi(


new GuzzleHttp\Client(),
$config
);
$input = new \Swagger\Client\Model\GetTimezonesRequest(); // \Swagger\Client\Model\GetTimezonesRequest | Input request

try {
$result = $apiInstance->addressGetTimezone($input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling AddressApi->addressGetTimezone: ', $e->getMessage(), PHP_EOL;
}
?>

Now provide a free-tier API key to authenticate, and you’re good to go! That’s all there is to it.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet