Is there a list of Pytz Timezones?
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
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