### Install with npm
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Install the library using npm. This is the standard method for Node.js projects.
```bash
npm install --save countries-and-timezones
```
--------------------------------
### Country Data Model Example
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
An example of the JSON structure representing a country, including its ID, name, and associated timezones.
```javascript
{
id: 'MX',
name: 'Mexico',
timezones: [
'America/Bahia_Banderas',
'America/Cancun',
'America/Chihuahua',
'America/Hermosillo',
'America/Matamoros',
'America/Mazatlan',
'America/Merida',
'America/Mexico_City',
'America/Monterrey',
'America/Ojinaga',
'America/Tijuana'
]
}
```
--------------------------------
### Timezone Data Model Example
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
An example of the JSON structure representing a timezone, detailing its name, associated countries, UTC offsets, DST information, and alias status.
```javascript
{
name: 'Asia/Tel_Aviv',
countries: [ 'IL' ],
utcOffset: 120,
utcOffsetStr: '+02:00',
dstOffset: 180,
dstOffsetStr: '+03:00',
aliasOf: 'Asia/Jerusalem',
deprecated: true
}
```
--------------------------------
### Get All Countries Data
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Retrieve an object containing data for all available countries. Each country is keyed by its ID.
```javascript
const ct = require("countries-and-timezones");
const countries = ct.getAllCountries();
console.log(countries);
/*
Prints:
{
AD: {
id: 'AD',
name: 'Andorra',
timezones: [ 'Europe/Andorra' ]
},
AE: {
id: 'AE',
name: 'United Arab Emirates',
timezones: [ 'Asia/Dubai' ]
},
AF: {
id: 'AF',
name: 'Afghanistan',
timezones: [ 'Asia/Kabul' ]
},
AG: {
id: 'AG',
name: 'Antigua and Barbuda',
timezones: [ 'America/Puerto_Rico' ]
},
...
}
*/
```
--------------------------------
### Get All Timezones Data
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Retrieve an object containing data for all available timezones. Each timezone is keyed by its name.
```javascript
const ct = require("countries-and-timezones");
const timezones = ct.getAllTimezones();
console.log(timezones);
/*
Prints:
{
"Africa/Abidjan": {
"name": "Africa/Abidjan",
"countries": [
"CI", "BF", "GH",
"GM", "GN", "ML",
"MR", "SH", "SL",
"SN", "TG"
],
"utcOffset": 0,
"utcOffsetStr": "+00:00",
"dstOffset": 0,
"dstOffsetStr": "+00:00",
"aliasOf": null
},
"Africa/Algiers": {
"name": "Africa/Algiers",
"countries": [
"DZ"
],
"utcOffset": 60,
"utcOffsetStr": "+01:00",
"dstOffset": 60,
"dstOffsetStr": "+01:00",
"aliasOf": null
},
"Africa/Bissau": {
"name": "Africa/Bissau",
"countries": [
"GW"
],
"utcOffset": 0,
"utcOffsetStr": "+00:00",
"dstOffset": 0,
"dstOffsetStr": "+00:00",
"aliasOf": null
},
...
}
*/
```
--------------------------------
### Get Countries for a Timezone
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Retrieves a list of countries that use a specified timezone. The first country in the list is considered the most relevant.
```javascript
const ct = require("countries-and-timezones");
const timezone = ct.getCountriesForTimezone("Europe/Zurich");
console.log(timezone);
```
--------------------------------
### Get Timezone by Name
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Retrieve a timezone's data using its name. The returned object includes the timezone name, associated countries, and UTC offset details.
```javascript
const ct = require("countries-and-timezones");
const timezone = ct.getTimezone("America/Los_Angeles");
console.log(timezone);
/*
Prints:
{
name: 'America/Los_Angeles',
countries: [ 'US' ],
utcOffset: -480,
utcOffsetStr: '-08:00',
dstOffset: -420,
dstOffsetStr: '-07:00',
aliasOf: null
}
*/
```
--------------------------------
### Get Most Relevant Country for a Timezone
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Retrieves the single most relevant country for a given timezone, based on geographical location. Useful when a timezone is associated with multiple countries.
```javascript
const ct = require("countries-and-timezones");
const timezone = ct.getCountryForTimezone("Europe/Zurich");
console.log(timezone);
```
--------------------------------
### Get Country by ID
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Retrieve a country's data using its unique ID. The returned object contains the country's ID, name, and associated timezones.
```javascript
const ct = require("countries-and-timezones");
const country = ct.getCountry("DE");
console.log(country);
/*
Prints:
{
id: 'DE',
name: 'Germany',
timezones: [ 'Europe/Berlin', 'Europe/Zurich' ]
}
*/
```
--------------------------------
### Get Timezones for a Country
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Retrieve an array of timezone objects associated with a given country ID. Each timezone object includes its name, associated countries, and offset details.
```javascript
const ct = require("countries-and-timezones");
const timezones = ct.getTimezonesForCountry("MX");
console.log(timezones);
/*
Prints:
[
{
"name": "America/Bahia_Banderas",
"countries": [ "MX" ],
"utcOffset": -360,
"utcOffsetStr": "-06:00",
"dstOffset": -300,
"dstOffsetStr": "-05:00",
"aliasOf": null
},
{
"name": "America/Cancun",
"countries": [ "MX" ],
"utcOffset": -300,
"utcOffsetStr": "-05:00",
"dstOffset": -300,
"dstOffsetStr": "-05:00",
"aliasOf": null
},
{
"name": "America/Chihuahua",
"countries": [ "MX" ],
"utcOffset": -420,
"utcOffsetStr": "-07:00",
"dstOffset": -360,
"dstOffsetStr": "-06:00",
"aliasOf": null
},
...
}
*/
```
--------------------------------
### Include via CDN in Browser
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Include the library in your HTML for browser usage. You can use the latest version or a specific version.
```html
```
--------------------------------
### options
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Available options for functions like getCountriesForTimezone and getCountryForTimezone.
```APIDOC
## options
Available options for functions are:
| Parameter | Type | Description |
| ------------ | ------- | -------------------------------------------------------------------------------------------------------------------- |
| `deprecated` | Boolean | Indicates if the result should include deprecated timezones or not. By default no deprecated timezones are included. |
```
--------------------------------
### .getAllCountries(options = {})
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Returns an object with the data of all countries. Accepts a parameter with `options`.
```APIDOC
## .getAllCountries(options = {})
### Description
Returns an object with the data of all countries. Accepts a parameter with `options`.
### Parameters
#### Path Parameters
- **options** (object) - Optional - Options for retrieving all country data.
### Request Example
```javascript
const ct = require("countries-and-timezones");
const countries = ct.getAllCountries();
console.log(countries);
```
### Response
#### Success Response
- An object where keys are country IDs and values are country objects.
#### Response Example
```json
{
"AD": {
"id": "AD",
"name": "Andorra",
"timezones": [ "Europe/Andorra" ]
},
"AE": {
"id": "AE",
"name": "United Arab Emirates",
"timezones": [ "Asia/Dubai" ]
}
}
```
```
--------------------------------
### .getAllTimezones(options = {})
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Returns an object with the data of all timezones. Accepts a parameter with `options`.
```APIDOC
## .getAllTimezones(options = {})
### Description
Returns an object with the data of all timezones. Accepts a parameter with `options`.
### Parameters
#### Path Parameters
- **options** (object) - Optional - Options for retrieving all timezone data.
### Request Example
```javascript
const ct = require("countries-and-timezones");
const timezones = ct.getAllTimezones();
console.log(timezones);
```
### Response
#### Success Response
- An object where keys are timezone names and values are timezone objects.
#### Response Example
```json
{
"Africa/Abidjan": {
"name": "Africa/Abidjan",
"countries": [ "CI", "BF", "GH" ],
"utcOffset": 0,
"utcOffsetStr": "+00:00",
"dstOffset": 0,
"dstOffsetStr": "+00:00",
"aliasOf": null
}
}
```
```
--------------------------------
### .getCountry(id, options = {})
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Returns a country referenced by its `id`. Accepts a parameter with `options`.
```APIDOC
## .getCountry(id, options = {})
### Description
Returns a country referenced by its `id`. Accepts a parameter with `options`.
### Parameters
#### Path Parameters
- **id** (string) - Required - The ID of the country to retrieve.
- **options** (object) - Optional - Options for retrieving the country data.
### Request Example
```javascript
const ct = require("countries-and-timezones");
const country = ct.getCountry("DE");
console.log(country);
```
### Response
#### Success Response
- **id** (string) - The country's ID.
- **name** (string) - The country's name.
- **timezones** (array) - An array of timezone names for the country.
#### Response Example
```json
{
"id": "DE",
"name": "Germany",
"timezones": [ "Europe/Berlin", "Europe/Zurich" ]
}
```
```
--------------------------------
### .getTimezonesForCountry(id, options = {})
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Returns an array with all the timezones of a country given its `id`. Accepts a parameter with `options`.
```APIDOC
## .getTimezonesForCountry(id, options = {})
### Description
Returns an array with all the timezones of a country given its `id`. Accepts a parameter with `options`.
### Parameters
#### Path Parameters
- **id** (string) - Required - The ID of the country.
- **options** (object) - Optional - Options for retrieving timezones for the country.
### Request Example
```javascript
const ct = require("countries-and-timezones");
const timezones = ct.getTimezonesForCountry("MX");
console.log(timezones);
```
### Response
#### Success Response
- An array of timezone objects for the specified country.
#### Response Example
```json
[
{
"name": "America/Bahia_Banderas",
"countries": [ "MX" ],
"utcOffset": -360,
"utcOffsetStr": "-06:00",
"dstOffset": -300,
"dstOffsetStr": "-05:00",
"aliasOf": null
}
]
```
```
--------------------------------
### .getCountriesForTimezone(name, options = {})
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Returns a list of countries that use a specified timezone. The first country in the list is considered the most relevant geographically.
```APIDOC
## .getCountriesForTimezone(name, options = {})
### Description
Returns a list of countries that use a specified timezone. The first country in the list is considered the most relevant geographically.
### Method
Not applicable (JavaScript function)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
#### Function Parameters
* **name** (string) - Required - The name of the timezone (e.g., "Europe/Zurich").
* **options** (object) - Optional - An object containing additional options. See [`options`](#options) for details.
### Request Example
```javascript
const ct = require("countries-and-timezones");
const timezone = ct.getCountriesForTimezone("Europe/Zurich");
console.log(timezone);
```
### Response
#### Success Response
Returns an array of country objects. Each object contains:
- **id** (string) - The country's ISO 3166-1 alpha-2 code.
- **name** (string) - The country's name.
- **timezones** (array of strings) - A list of timezones used in the country.
#### Response Example
```json
[
{
"id": "CH",
"name": "Switzerland",
"timezones": [
"Europe/Zurich"
]
},
{
"id": "DE",
"name": "Germany",
"timezones": [
"Europe/Berlin",
"Europe/Zurich"
]
},
{
"id": "LI",
"name": "Liechtenstein",
"timezones": [
"Europe/Zurich"
]
}
]
```
```
--------------------------------
### .getCountryForTimezone(name, options = {})
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Returns the most geographically relevant country that uses a specified timezone.
```APIDOC
## .getCountryForTimezone(name, options = {})
### Description
Returns the most geographically relevant country that uses a specified timezone.
### Method
Not applicable (JavaScript function)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
#### Function Parameters
* **name** (string) - Required - The name of the timezone (e.g., "Europe/Zurich").
* **options** (object) - Optional - An object containing additional options. See [`options`](#options) for details.
### Request Example
```javascript
const ct = require("countries-and-timezones");
const timezone = ct.getCountryForTimezone("Europe/Zurich");
console.log(timezone);
```
### Response
#### Success Response
Returns a country object. The object contains:
- **id** (string) - The country's ISO 3166-1 alpha-2 code.
- **name** (string) - The country's name.
- **timezones** (array of strings) - A list of timezones used in the country.
#### Response Example
```json
{
"id": "CH",
"name": "Switzerland",
"timezones": [
"Europe/Zurich"
]
}
```
```
--------------------------------
### .getTimezone(name)
Source: https://github.com/manuelmhtr/countries-and-timezones/blob/dev/README.md
Returns a timezone referenced by its `name`.
```APIDOC
## .getTimezone(name)
### Description
Returns a timezone referenced by its `name`.
### Parameters
#### Path Parameters
- **name** (string) - Required - The name of the timezone to retrieve.
### Request Example
```javascript
const ct = require("countries-and-timezones");
const timezone = ct.getTimezone("America/Los_Angeles");
console.log(timezone);
```
### Response
#### Success Response
- **name** (string) - The timezone's name.
- **countries** (array) - An array of country IDs associated with this timezone.
- **utcOffset** (number) - The UTC offset in minutes.
- **utcOffsetStr** (string) - The UTC offset as a string (e.g., "-08:00").
- **dstOffset** (number) - The Daylight Saving Time offset in minutes.
- **dstOffsetStr** (string) - The Daylight Saving Time offset as a string (e.g., "-07:00").
- **aliasOf** (string|null) - The name of the timezone this is an alias of, or null.
#### Response Example
```json
{
"name": "America/Los_Angeles",
"countries": [ "US" ],
"utcOffset": -480,
"utcOffsetStr": "-08:00",
"dstOffset": -420,
"dstOffsetStr": "-07:00",
"aliasOf": null
}
```
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.