get_timezone_name(dt_or_tzinfo={ ' territory_zones ' : { ' 001 ' : [ ' Etc/GMT ' , ' Etc/GMT-1 ' , ' Etc/GMT- ... ,
width=' long ' ,
uncommon=True,
locale=' de_DE ' )
|
|
Return the localized display name for the given timezone. The timezone
may be specified using a datetime or tzinfo object.
>>> from pytz import timezone
>>> dt = time(15, 30, tzinfo=timezone('America/Los_Angeles'))
>>> get_timezone_name(dt, locale='en_US')
u'Pacific Standard Time'
>>> get_timezone_name(dt, width='short', locale='en_US')
u'PST'
If this function gets passed only a tzinfo object and no concrete
datetime, the returned display name is indenpendent of daylight savings
time. This can be used for example for selecting timezones, or to set the
time of events that recur across DST changes:
>>> tz = timezone('America/Los_Angeles')
>>> get_timezone_name(tz, locale='en_US')
u'Pacific Time'
>>> get_timezone_name(tz, 'short', locale='en_US')
u'PT'
If no localized display name for the timezone is available, and the timezone
is associated with a country that uses only a single timezone, the name of
that country is returned, formatted according to the locale:
>>> tz = timezone('Europe/Berlin')
>>> get_timezone_name(tz, locale='de_DE')
u'Deutschland'
>>> get_timezone_name(tz, locale='pt_BR')
u'Hor\xe1rio Alemanha'
On the other hand, if the country uses multiple timezones, the city is also
included in the representation:
>>> tz = timezone('America/St_Johns')
>>> get_timezone_name(tz, locale='de_DE')
u"Kanada (St. John's)"
The uncommon parameter can be set to True to enable the use of timezone
representations that are not commonly used by the requested locale. For
example, while in frensh the central europian timezone is usually
abbreviated as "HEC", in Canadian frensh, this abbreviation is not in common
use, so a generic name would be chosen by default:
>>> tz = timezone('Europe/Paris')
>>> get_timezone_name(tz, 'short', locale='fr_CA')
u'France'
>>> get_timezone_name(tz, 'short', uncommon=True, locale='fr_CA')
u'HEC'
- Parameters:
dt_or_tzinfo - the datetime or tzinfo object that determines
the timezone; if a tzinfo object is used, the
resulting display name will be generic, i.e.
independent of daylight savings time; if None , the
current date in UTC is assumed
width - either "long" or "short"
uncommon - whether even uncommon timezone abbreviations should be used
locale - the Locale object, or a locale string
- Returns:
unicode
- the timezone display name
|