No Result
View All Result
DevRescue
  • Home
  • Python
  • Lists
  • Movies
  • Finance
  • Opinion
  • About
  • Contact Us
  • Home
  • Python
  • Lists
  • Movies
  • Finance
  • Opinion
  • About
  • Contact Us
DevRescue
Home Blog Python

Python Timezone List With Code

by Khaleel O.
June 8, 2021
in Python
Reading Time: 4 mins read
A A
List of Timezones In Python
List of Timezones in Python

To get a python timezone list, we can use the powerful pytz library. If you do not have pytz installed you can do so by using the pip install pytz command at the command line. Of course you must have Python and pip installed beforehand.

We will be using Python 3.8.10 in this tutorial.

import pytz

print(pytz.all_timezones)

#Outputs
#['Africa/Abidjan', 'Africa/Accra', 'Africa/Addis_Ababa', 'Africa/Algiers', 'Africa/Asmara'...'UTC', #'Universal', 'W-SU', 'WET', 'Zulu']

Using pytz.all_timezones will give you a very long list of type LazyList of World Time Zones with their long names. There is another way we can accomplish this. See below:

import pytz

print(pytz.all_timezones_set)

#Outputs
#LazySet({'Africa/Windhoek', 'Asia/Tashkent', 'Egypt', 'America/Santiago'...'Australia/Yancowinna', #'America/Mazatlan'})

Using pytz.all_timezones_set will give you a long set of type LazySet of World Time Zones with their long names.

There is a third way that we can get a list of timezones. See below:

import pytz

print(pytz.common_timezones)

#Outputs
#['Africa/Abidjan', 'Africa/Accra', 'Africa/Addis_Ababa', 'Africa/Algiers'...'US/Mountain', 'US/Pacific', 'UTC']

Using pytz.common_timezones will give us a slightly smaller LazyList of the more common world timezones.

The first two timezone lists have the same amount of elements (593) but the common_timezones list has 439 elements.

import pytz

print(len(pytz.all_timezones_set))
print(len(pytz.all_timezones))
print(len(pytz.common_timezones))

#Outputs
#593
#593
#439

We can take this a step further and use the pandas package to output any of these lists to a csv file for further reference. We can easily install pandas with the command pip install pandas at the command line and execute the following code. We will attempt to save the pytz.all_timezones_set set to a CSV file on disk:

import pandas as pd  
import pytz

       
df = pd.DataFrame(pytz.all_timezones_set) 
    
#Saving DataFrame to Local Disk and Folder as CSV file
df.to_csv('AllTZ.csv') 

The above code should save a CSV file with 2 columns and 594 rows (the first row can be deleted) to the disk in your working directory with the name AllTZ.csv. Below is a pic of what that list would look like in MS Excel:

List of Timezones in Python
Your CSV File Should Look Like This

We hope this article helped you to be able to acquire a list of time zones in python.

You can find the documentation for the pytz library HERE.

You can find the documentation for the pandas library HERE.

We also have a searchable list of time zones in python (common) with Long Name and UTC Offset HERE. Thanks for reading! 👌👌👌

Previous Post

for i in range Python 3 Tutorial With Examples

Next Post

Python Timezone Now Tutorial

Khaleel O.

Khaleel O.

I love to share, educate and help developers. I have 14+ years experience in IT. Currently transitioning from Systems Administration to DevOps. Avid reader, intellectual and dreamer. Enter Freely, Go safely, And leave something of the happiness you bring.

Related Posts

Python

Python Fibonacci Recursive Solution

by Khaleel O.
January 16, 2024
0
0

Let's do a Python Fibonacci Recursive Solution. Let's go! 🔥🔥🔥 The Fibonacci sequence is a series of numbers in which...

Read moreDetails
Python

Python Slice String List Tuple

by Khaleel O.
January 16, 2024
0
0

Let's do a Python Slice string list tuple how-to tutorial. Let's go! 🔥🔥🔥 In Python, a slice is a feature...

Read moreDetails
Python

Python Blowfish Encryption Example

by Khaleel O.
January 14, 2024
0
0

Let's do a Python Blowfish Encryption example. Let's go! 🔥 🔥 Blowfish is a symmetric-key block cipher algorithm designed for...

Read moreDetails
Python

Python Deque Methods

by Khaleel O.
January 14, 2024
0
0

In this post we'll list Python Deque Methods. Ready? Let's go! 🔥🔥🔥 A deque (double-ended queue) in Python is a...

Read moreDetails

DevRescue © 2021 All Rights Reserved. Privacy Policy. Cookie Policy

Manage your privacy

To provide the best experiences, we and our partners use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us and our partners to process personal data such as browsing behavior or unique IDs on this site and show (non-) personalized ads. Not consenting or withdrawing consent, may adversely affect certain features and functions.

Click below to consent to the above or make granular choices. Your choices will be applied to this site only. You can change your settings at any time, including withdrawing your consent, by using the toggles on the Cookie Policy, or by clicking on the manage consent button at the bottom of the screen.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
Manage options
  • {title}
  • {title}
  • {title}
Manage your privacy
To provide the best experiences, DevRescue.com will use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
Manage options
  • {title}
  • {title}
  • {title}
No Result
View All Result
  • Home
  • Python
  • Lists
  • Movies
  • Finance
  • Opinion
  • About
  • Contact Us

DevRescue © 2022 All Rights Reserved Privacy Policy