Get Time Zones for a Country in JavaScript

Cloudmersive
1 min readMay 17, 2021

--

Attempting to configure time zones within your websites or applications can be a challenging task, especially when taking daylight savings time into consideration. To avoid the need for creating a time zone conversion model, we are going to discuss how you can use the following API in JavaScript to simplify time zone retrieval by country or ISO code.

Let’s kick things off by installing the jQuery library:

bower install jquery

After the installation is complete, we are ready to call the get time zones function:

var settings = {
"url": "https://api.cloudmersive.com/validate/address/country/get-timezones",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/json",
"Apikey": "YOUR-API-KEY-HERE"
},
"data": JSON.stringify({
"CountryCodeOrName": "<string>"
}),
};
$.ajax(settings).done(function (response) {
console.log(response);
});

The time zone name or names will be returned along with the current time, country name, ISO two-letter code, FIPS two-letter code, and the three-letter code. If you need to obtain an API key, simply visit the Cloudmersive website and register for a free account; this will provide 800 monthly calls/month with no expiration.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet