PYnative

Python Programming

  • Learn Python
  • Exercises
  • Quizzes
  • Code Editor
  • Tricks
Home » Python » Python DateTime » List All TimeZones in Python

List All TimeZones in Python

Updated on: December 5, 2021 | 1 Comment

In this tutorial, we will learn how to get the list of timezones available in the world in Python.

The pytz library has implemented a timezone class for handling arbitrary fixed offsets from UTC and timezones.

pytz has a huge list of timezones available in the world. This is helpful if you don’t know the exact name of the timezone to create a date and time in that timezone.

It provides a list with more than 500 names representing common timezones across the world.

This module has methods to create datetime objects with localized timezones. In addition to the base class methods, it has some of the following methods and attributes, useful in finding the supported timezone strings.

Below are the methods and attributes to get all timezone names: –

  • all_timezones: Returns the list of all the timezones supported by the timezone module
  • all_timezones_set: Returns a set with all the timezones supported by the timezone module
  • common_timezones and common_timezones_set: Provides a list and set of the commonly used timezones.
  • country_names: Returns a dictionary with the country’s ISO Alpha 2 code as key and full country name as its value.
  • country_timezones: Returns a dictionary with Country code as Key and supported timezones as its value.

Read our complete guide on timezone in Python to work with the timezones.

Table of contents

  • Get List of All Timezones Name
  • Get Common Timezones
  • Get Timezone of a Any Country

Get List of All Timezones Name

First, Install the pytz module if not installed using the pip install pytz command. Use the pytz.all_timezones attribute to get the list of available timezone in the world.

import pytz

print('Timezones')
for timeZone in pytz.all_timezones:
    print(timeZone)

Output:

Timezones

Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
...
US/Mountain
US/Pacific
US/Samoa
UTC
Universal

Count: 592

There is another attribute that returns a set of timezones instead of a list.

import pytz

print('Timezones')
for timeZone in pytz.all_timezones_set:
    print(timeZone)

Note: This list contains a lot of alias names, such as US/Central for the timezone that is properly called America/Mexico_City

Read our complete guide on timezone in Python

Get Common Timezones

The above list is vast. If you want to get the most commonly used timezone in the world, use the pytz.common_timezones attribute.

import pytz

print('Most commonly used timezones')
for timeZone in pytz.common_timezones:
    print(timeZone)


print(len(pytz.common_timezones))
# Output 440

Get Timezone of a Any Country

Use the pytz.country_timezones['country_name'] attribute to get the timezone of any country.

Let’s see how to get all the timezone of the united states.

import pytz

print('US TimeZones')
for timeZone in pytz.country_timezones['US']:
    print(timeZone)

Output:

US TimeZones

America/New_York
America/Detroit
America/Kentucky/Louisville
America/Kentucky/Monticello
America/Indiana/Indianapolis
America/Indiana/Vincennes
America/Indiana/Winamac
America/Indiana/Marengo
America/Indiana/Petersburg
America/Indiana/Vevay
America/Chicago
America/Indiana/Tell_City
America/Indiana/Knox
America/Menominee
America/North_Dakota/Center
America/North_Dakota/New_Salem
America/North_Dakota/Beulah
America/Denver
America/Boise
America/Phoenix
America/Los_Angeles
America/Anchorage
America/Juneau
America/Sitka
America/Metlakatla
America/Yakutat
America/Nome
America/Adak
Pacific/Honolulu

Note: Use pytz.country_names to get the all country names if you don’t know the exact name of the country.

import pytz

print('country Names with Code')
for code, name in pytz.country_names.items():
    print(code, ':', name)

print('Country full name =', pytz.country_names['IN'])

Filed Under: Python, Python DateTime

Did you find this page helpful? Let others know about it. Sharing helps me continue to create free Python resources.

TweetF  sharein  shareP  Pin

About Vishal

Founder of PYnative.com I am a Python developer and I love to write articles to help developers. Follow me on Twitter. All the best for your future Python endeavors!

Related Tutorial Topics:

Python Python DateTime

Python Exercises and Quizzes

Free coding exercises and quizzes cover Python basics, data structure, data analytics, and more.

  • 15+ Topic-specific Exercises and Quizzes
  • Each Exercise contains 10 questions
  • Each Quiz contains 12-15 MCQ
Exercises
Quizzes

Posted In

Python Python DateTime
TweetF  sharein  shareP  Pin

  Python DateTime

  • Python DateTime Guide
  • Python Get Current DateTime
  • Python DateTime Formatting
  • Python String to DateTime
  • Python Timestamp
  • Python Timedelta
  • Python TimeZones
  • List All TimeZones in Python

All Python Topics

Python Basics Python Exercises Python Quizzes Python File Handling Python OOP Python Date and Time Python Random Python Regex Python Pandas Python Databases Python MySQL Python PostgreSQL Python SQLite Python JSON

About PYnative

PYnative.com is for Python lovers. Here, You can get Tutorials, Exercises, and Quizzes to practice and improve your Python skills.

Explore Python

  • Learn Python
  • Python Basics
  • Python Databases
  • Python Exercises
  • Python Quizzes
  • Online Python Code Editor
  • Python Tricks

Follow Us

To get New Python Tutorials, Exercises, and Quizzes

  • Twitter
  • Facebook
  • Sitemap

Legal Stuff

  • About Us
  • Contact Us

We use cookies to improve your experience. While using PYnative, you agree to have read and accepted our Terms Of Use, Cookie Policy, and Privacy Policy.

Copyright © 2018–2023 pynative.com