Why do Datastore datetimes look different in appengine console vs appengine dashboard?

隐身守侯 提交于 2020-01-05 11:05:17

问题


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:


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)



来源:https://stackoverflow.com/questions/29949938/why-do-datastore-datetimes-look-different-in-appengine-console-vs-appengine-dash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!