For dateutil
:
from dateutil.zoneinfo import getzoneinfofile_stream, ZoneInfoFile
ZoneInfoFile(getzoneinfofile_stream()).zones.keys()
>>> ['Asia/Ujung_Pandang',
'America/Porto_Velho',
'America/La_Paz',
'America/Caracas',
'Europe/Malta',
'Etc/GMT-13',
'Atlantic/Bermuda',
...]
pytz
is a little easier
import pytz
pytz.all_timezones
>>> ['Africa/Abidjan',
'Africa/Accra',
'Africa/Addis_Ababa',
'Africa/Algiers',
'Africa/Asmara',
'Africa/Asmera',
'Africa/Bamako',
'Africa/Bangui',
'Africa/Banjul',
'Africa/Bissau',
'Africa/Blantyre',
'Africa/Brazzaville',
...]
Note that dateutil
prefers to use the operating system to determine timezone info. pytz
uses its own zone files. While there are probably advantages to each, pytz
provides more consistency if you don't want to manage time zones at the system level.
pytz.all_timezones
gives a list of the timezone names that can be used withpytz
. Sometimes timezone conversions withdateutil
andpytz
can produce different results. – Sent