Why doesn't appengine auto-convert datetime to UTC when calling put()

你离开我真会死。 提交于 2019-12-04 06:26:47
Guido van Rossum

The solution is to remove the tzinfo completely from the time after converting to UTC.

timestamp = timestamp.replace(tzinfo=None)

Here my working example:

if my_date.utcoffset():
    my_date = (my_date - my_date.utcoffset()).replace(tzinfo=None)

I ran into this using http://hnrss.org/. This was my solution.

    import datetime
    from dateutil import parser

    your_date_string = 'Mon, 24 Oct 2016 16:49:47 +0000'

    your_date = parser.parse('your_date_string')
    # your_date is now a datetime.datetime object

    your_date_minus_tz = your_date.replace(tzinfo=None)

Now try your put() and you should see 2016-10-24 16:49:47 in the Cloud datastore.

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