datetime 对象没有 tzinfo 对象。所以请试试这个
import pytz
from pytz import timezone
query = GuestMessage.all().get()
current = query.date
user_tz = timezone('Asia/Singapore')
current = current.replace(tzinfo=pytz.utc).astimezone(user_tz)
self.response.write(current.strftime('%Y-%m-%d %H:%M:%S %z')) # 2013-05-22 19:54:14 +0800
self.response.write(current.strftime('%Y-%m-%d %H:%M:%S %Z')) # 2013-05-22 19:54:14 SGT
从请求标头中查找时区:
county_code = self.request.headers['X-Appengine-Country'] # Return County code like SG, IN etc.
tz = pytz.country_timezones(county_code)
如果您正在获取ImportError: No module named pytz
,请从此处下载源代码:pypi.python.org/pypi/gaepytz。然后将 pytz 目录移动到应用引擎项目的根目录