Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python timezone full names

pytz provides list of timezones in formats like America/Chicago, America/Los_Angeles, Asia/Kolkata or the tz abbreviation.

I want the full name for timezones.

  • Central Standard Time
  • Pacific Standard Time
  • Indian Standard Time

Is this possible in Python?

like image 788
MavWolverine Avatar asked Aug 09 '14 19:08

MavWolverine


1 Answers

The Unicode CLDR project contains many localized strings, including the human-readable names of time zones in many different languages.

A quick search for Python implementations of CLDR found the Babel library. An example shown in this part of the documentation is as follows:

>>> british = get_timezone('Europe/London')
>>> format_datetime(dt, 'H:mm zzzz', tzinfo=british, locale='en_US')
u'16:30 British Summer Time'

Here we can see that at the date and time specified by the dt variable, and the IANA time zone (as used by pytz) of Europe/London, the English display name is "British Summer Time".

There's also an example of how to get just the generic time zone name, without regard to a specific date:

>>> from babel import Locale
>>> from babel.dates import get_timezone_name, get_timezone

>>> tz = get_timezone('Europe/Berlin')
>>> get_timezone_name(tz, locale=Locale.parse('pt_PT'))
u'Hor\xe1rio Alemanha'

That is, the Europe/Berlin time zone has the Portugese name of "Horário Alemanha".

like image 196
Matt Johnson-Pint Avatar answered Oct 04 '22 04:10

Matt Johnson-Pint