Why do Datastore datetimes look different in appen

2019-08-11 01:25发布

I have a very simple NDB model for which I'm entering Date-of-Birth for a user:

class Contact(ndb.Model):
    first_name= ndb.StringProperty()
    last_name= ndb.StringProperty()
    dob = ndb.DateTimeProperty()
contact1_dob = datetime.strptime('12/17/1989', "%m/%d/%Y").date()
contact1 = Contact(first_name='Homer', last_name='Simpson', dob=contact1_dob )
contact1_result = contact1.put()

Loading into the datastore works fine, and when I look at the data via the Google Appengine dashboard https://appengine.google.com/ the DOB looks perfect e.g. 1989-12-17 00:00:00

But when I look at the data via the appengine console https://console.developers.google.com the DOB is four hours behind (I'm in New York) e.g. 1989-12-16 20:00:00

I can only guess this is a timezone issue but if it were wouldn't the dates in both the dashboard and the console match?

Also if I retrieve the entity via a .get() call and view the raw data the date is exactly as I entered it, e.g. 1989-12-17 00:00:00, which is what I want.

So why is the appengine console not rendering datastore dates accurately?

1条回答
贪生不怕死
2楼-- · 2019-08-11 02:16

The old dataviewer always displays as UTC, the new console attempts to display in your timezone. Datetimes are always UTC from inside your application (so if you do a .put() or .get() it will be saved as UTC)

So you are setting it at midnight UTC inside your app and doing a put, then looking at it in the new console which is showing you 20:00:00T (8pm EST) the day before

There have been reported issues around timezones when using Remote API... not sure if you're using that for any of your puts/gets... might also play a part (but I thought they had those mostly fixed by now)

查看更多
登录 后发表回答