开发者

Converting string representation of time to date time in app engine

In standard python, I can convert a string representation of time into datetime doing this:

date_string = u'Tue, 13 Sep 2011 02:38:59 GMT';
date_object = datetime.strptime(date_string, '%a, %d %b %Y %H:%M:%S %Z');

This works fine until I invoke the same over app engine where I get the error:

time data did not match format:  data=2011-09-13 02:38:59  fmt=%a, %d %b %Y %H:%M:%S %Z

How would I convert开发者_运维知识库 this date string correctly so I can get a datetime representation?


Your error message indicates that you're not really passing Tue, 13 Sep 2011 02:38:59 GMT, but 2011-09-13 02:38:59. Are you sure you pass the correct parameters to strptime?

My python works just fine for the following:

datetime.strptime(u'Tue, 13 Sep 2011 02:38:59 GMT', "%a, %d %b %Y %H:%M:%S %Z")
# returns datetime.datetime(2011, 9, 13, 2, 38, 59)

This also works fine for me:

from dateutil imoprt parser as dparser
dparser.parse("Tue, 13 Sep 2011 02:38:59 GMT")
# returns datetime.datetime(2011, 9, 13, 2, 38, 59, tzinfo=tzutc())
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜