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
Release: 2024-10-31 20:46:02
Original
367 people have browsed it

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>
Copy after login

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',
 ...]
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template