ndb – Grey Panthers Savannah https://grey-panther.net Just another WordPress site Sun, 08 May 2022 11:39:11 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.1 206299117 Converting datetime to UTC in python https://grey-panther.net/2013/02/converting-datetime-to-utc-in-python.html https://grey-panther.net/2013/02/converting-datetime-to-utc-in-python.html#respond Thu, 07 Feb 2013 17:06:00 +0000 So you need to convert a python datetime object which has a timezone set (“aware” in the Python nomenclature) to an UTC one with no timezone set (“naive”), for example because NDB on GAE can’t store anything else. The solution will look something like this:

date = date.astimezone(tz.tzutc()).replace(tzinfo=None)

For searcheability: the exception thrown by NDB if you fail to do this is “NotImplementedError: DatetimeProperty updated_at can only support UTC. Please derive a new Property to support alternative timezones.”

]]>
https://grey-panther.net/2013/02/converting-datetime-to-utc-in-python.html/feed 0 17