Babel 0.9.5 및 pytz 2010b에서 나를 위해 작동합니다.
py.tz
#!/usr/bin/env python
import pytz
import babel.dates
tz = pytz.timezone('America/New_York')
print babel.dates.get_timezone_location(tz)
출력
$ python tz.py
United States (New York) Time
당신은 어떻게 그것을 실행하는? 어떤 버전?
보유하고있는 버전에 문제가 있다면 왜 대륙/도시 항목을 사용하지 않을까요?
여기가 출발점입니다. 대륙과 도시를 모두 결정하므로 원하는 형식으로 서식을 지정할 수 있습니다.
tzs.py
#!/usr/bin/env python
import pytz
import babel.dates
import re
country_timezones = {}
for (country, tzlist) in pytz.country_timezones.iteritems():
country_name = pytz.country_names[country]
cities = []
for timezone in tzlist:
# remove continent
city = re.sub(r'^[^/]*/', r'', timezone)
# Argentina has an extra "Argentina/" on my system (pytz 2010b)
city = re.sub(country_name + '/', '', city)
# Indiana and North Dakota have different rules by country
# change Indiana/Location to Location, Indiana
city = re.sub(r'^([^/]*)/(.*)', r'\2, \1', city)
# change underscores to spaces
city = re.sub(r'_', r' ', city)
cities.append(city)
country_timezones[country_name] = cities
for country in sorted(country_timezones):
print country
for city in sorted(country_timezones[country]):
print "\t%s" % (city)
출력
Aaland Islands
Mariehamn
Afghanistan
Kabul
...
Indonesia
Jakarta
Jayapura
Makassar
Pontianak
...
United States
Adak
Anchorage
Boise
Center, North Dakota
Chicago
Denver
Detroit