Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a list of Pytz Timezones?

I would like to know what are all the possible values for the timezone argument in the Python library pytz. How to do it?

like image 983
ipegasus Avatar asked Dec 13 '12 19:12

ipegasus


People also ask

What is pytz timezone?

The pytz package encourages using UTC for internal timezone representation by including a special UTC implementation based on the standard Python reference implementation in the Python documentation. The UTC timezone unpickles to be the same instance, and pickles to a smaller size than other pytz tzinfo instances.

Does pytz account for daylight savings?

Timedelta and DSTpytz will help you to tell if an date is under DST influence by checking dst() method.

What is pytz?

pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher. It also solves the issue of ambiguous times at the end of daylight saving time, which you can read more about in the Python Library Reference ( datetime. tzinfo ).

Is pytz built in Python?

pytz is a Python module mostly used for resolving the issues related to time zone differences. This module determines the time of any region using the local timezone name taking UTC time as the reference. The datetime is a python built-in library.


2 Answers

You can list all the available timezones with pytz.all_timezones:

In [40]: import pytz In [41]: pytz.all_timezones Out[42]:  ['Africa/Abidjan',  'Africa/Accra',  'Africa/Addis_Ababa',  ...] 

There is also pytz.common_timezones:

In [45]: len(pytz.common_timezones) Out[45]: 403  In [46]: len(pytz.all_timezones) Out[46]: 563 
like image 171
unutbu Avatar answered Sep 20 '22 18:09

unutbu


Don't create your own list - pytz has a built-in set:

import pytz set(pytz.all_timezones_set)   >>> {'Europe/Vienna', 'America/New_York', 'America/Argentina/Salta',..} 

You can then apply a timezone:

import datetime tz = pytz.timezone('Pacific/Johnston') ct = datetime.datetime.now(tz=tz) >>> ct.isoformat() 2017-01-13T11:29:22.601991-05:00 

Or if you already have a datetime object that is TZ aware (not naive):

# This timestamp is in UTC my_ct = datetime.datetime.now(tz=pytz.UTC)  # Now convert it to another timezone new_ct = my_ct.astimezone(tz) >>> new_ct.isoformat() 2017-01-13T11:29:22.601991-05:00 
like image 42
chribsen Avatar answered Sep 20 '22 18:09

chribsen