I'm using Google App Engine with python. And I can't install third party library.
I though this should work, but it actually runs without error but it returns current time timezone is not applied.
What did I do wrong?
from datetime import tzinfo, timedelta, datetime
class Seoul_tzinfo(tzinfo):
def utcoffset(self, dt):
return timedelta(hours=9)
def dst(self, dt):
return timedelta(0)
greeting.date = datetime.now( Seoul_tzinfo() )
I'm running python 2.6.5 and your code seems to work fine. I tweaked it to output my local time and your time adjusted one;
Are you sure it's not something having to do with your greeting class?
Are you talking about when the entity is fetched from the database? If so, appengine stores all dt properties in UTC; when you put(), it simply discards the tz info. The wisest thing would be to convert your dt to UTC (using astimezone()), and convert back when you fetch it from the datastore.
(See http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#DateTimeProperty )
You need to implement a
tzinfo
class with ALL the proper methods to do what you want to do.The documentation says that
tzinfo
is an abstract class that if to be used withdatetime
objects needs to be made a concrete class with proper methods.Specifically take a look at this from the documentation: