datetime.strptime works in python but fails in app engine

111 views
Skip to first unread message

lenza

unread,
Feb 24, 2009, 2:47:33 PM2/24/09
to Google App Engine
I am trying to parse dates in an App Engine app.
datetime.datetime.strptime is failing with a format error in the
development environment with the following error:

ERROR 2009-02-24 7:37:03,909 __init__.py] time data did not match
format: data=2009-02-24, 11:28AM PST fmt=%Y-%m-%d, %I:%M%p %Z

However, this works fine in Python:

>>> import datetime
>>> datetime.datetime.strptime("2009-02-24, 11:28AM PST", "%Y-%m-%d, %I:%M%p %Z")
datetime.datetime(2009, 2, 24, 11, 28)

This issue was previously reported here:
http://groups.google.com/group/google-appengine/browse_frm/thread/b36efa0ad3da8894

As Mariza suggests there, everything works fine when the timezone is
left out of the parsing. The same occurs for time.strptime. Anyone
know what is causing this or have a good workaround?

lenza

unread,
Feb 27, 2009, 11:08:32 PM2/27/09
to Google App Engine
It turns out the answer to this is that strptime in python does not
really support timezones: "datetime.datetime.strptime('PDT', '%Z')"
will throw ValueError whenever locale time is not PDT (or PST). "UTC"
and "GMT" don't throw an exception, but are not actually taken into
consideration. So, any python gurus out there know a reliable way to
convert from a string that contains a timezone to a UTC datetime?

Lenza
blog.lenza.org

On Feb 24, 11:47 am, lenza <le...@lenza.org> wrote:
> I am trying to parse dates in an App Engine app.
> datetime.datetime.strptime is failing with a format error in the
> development environment with the following error:
>
> ERROR    2009-02-24 7:37:03,909 __init__.py]timedata did not match
> format:  data=2009-02-24, 11:28AM PST  fmt=%Y-%m-%d, %I:%M%p %Z
>
> However, this works fine in Python:
>
> >>> import datetime
> >>> datetime.datetime.strptime("2009-02-24, 11:28AM PST", "%Y-%m-%d, %I:%M%p %Z")
>
> datetime.datetime(2009, 2, 24, 11, 28)
>
> This issue was previously reported here:http://groups.google.com/group/google-appengine/browse_frm/thread/b36...
>
> As Mariza suggests there, everything works fine when the timezone is
> left out of the parsing.  The same occurs fortime.strptime.  Anyone
Reply all
Reply to author
Forward
0 new messages