Get all available timezones

I'm currently working on an application that is required to support multiple timezones.

For that, I'm using the dateutil library. Now, I need a way to present the user a list of all available timezones the dateutil library supports.

Also, is it advisable to store the tz as strings in the database like "Europe/Berlin"?


dateutil will use the OS timezone info, but does carry it's own compressed timezone info file too.

You could list the available names from the utility code that loads this data:

from dateutil.zoneinfo import get_zonefile_instance
zonenames = list(get_zonefile_instance().zones)

You'd need to sort and filter that list a little; there are both abbreviated (3 letter) timezone codes as well as "region/city" entries in this list.

Storing those names in a database is just fine.

Note that this loads all data into memory; if that's not desirable you'd need to load the tar file yourself:

import os
import tarfile
import dateutil.zoneinfo

zi_path = os.path.abspath(os.path.dirname(dateutil.zoneinfo.__file__))
zonesfile =
    os.path.join(zi_path, dateutil.zoneinfo.ZONEFILENAME))
zonenames = [ for zn in zonesfile.getmembers()
             if not zn.isdir() and != dateutil.zoneinfo.METADATA_FN]

For dateutil:

from dateutil.zoneinfo import getzoneinfofile_stream, ZoneInfoFile
>>> ['Asia/Ujung_Pandang',

pytz is a little easier

import pytz
>>> ['Africa/Abidjan',

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.

Need Your Help

Best method for parsing date formats during import datas

java date parsing date-format

I created method for parsing a view different date formats during data import (400 K records). My method catches ParseException and trying to parse date with next format when it's different.

ListView exception for Images + Text

java android

I am trying to create a simple Icon+Text ListView but it does not work.