Home >Backend Development >Python Tutorial >How to Get a List of Timezones Supported by Pytz in Python?

How to Get a List of Timezones Supported by Pytz in Python?

Linda Hamilton
Linda HamiltonOriginal
2024-10-31 20:46:02358browse

How to Get a List of Timezones Supported by Pytz in Python?

Obtain a List of Available Timezones in Pytz

Finding the supported timezones within the Pytz library for Python is a common requirement. Here's how you can accomplish this:

Method 1: Utilize pytz.all_timezones

The pytz.all_timezones attribute provides a comprehensive list of every supported timezone in the library. To retrieve this list:

<code class="python">import pytz
pytz.all_timezones</code>

Method 2: Leverage pytz.common_timezones

For a subset of commonly used timezones, you can also utilize pytz.common_timezones, which contains a smaller but practical list.

Example Output:

Below is an example output using Method 1:

['Africa/Abidjan',
 'Africa/Accra',
 'Africa/Addis_Ababa',
 ...]

By leveraging these methods, you can effortlessly obtain a list of all or a subset of timezones supported by Pytz.

The above is the detailed content of How to Get a List of Timezones Supported by Pytz in Python?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn