How to Get a Country’s Time Zone in Node.JS

When expanding into international commerce, your organization will need to consider the many adjustments that need to be made to accommodate your partners and clients. For example, it’s necessary for your systems to take into account the various time zones across the globe. The following API will help you retrieve an input country’s time zones as well as its ISO two-letter code, FIPS two-letter code, and three-letter code to aid in your business operations.

Image for post
Image for post

First, we will need to run this command to install the SDK:

npm install cloudmersive-validate-api-client –save

You can also add this snippet to your package.json:

"dependencies": {
"cloudmersive-validate-api-client": "^1.2.4"
}

Then, you can call our function, AddressGetTimezone:

var CloudmersiveValidateApiClient = require('cloudmersive-validate-api-client');
var defaultClient = CloudmersiveValidateApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveValidateApiClient.AddressApi();var input = new CloudmersiveValidateApiClient.GetTimezonesRequest(); // GetTimezonesRequest | Input requestvar callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.addressGetTimezone(input, callback);

Now, you can easily retrieve time zone data for any location! You can get your personal API Key from the Cloudmersive website, giving you access to up to 800 calls across our library of APIs.

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