datetime usage for pagination
I want to output the datetime as a HTTP GET parameter like this
2011-04-11 12:09:21.366575
Instead the following output appears
April 11, 2011, 12:09 p.m.
This change took place with an upgrade of seemingly other components so I don't understand why it changed. The code is the same and what differs is the environment
datetime.strptime(bookmark[:-7], "%Y-%m-%d %H:%M:%S")
Can you explain what I need to do to get the data on the format like the first? I am passing on the bookmark parameter to do pagination like mentioned in this article.
Thank you
UPDATE: The code I got is
bookmark = self.request.get("bookmark") if self.request.get('bookmark') else self.request.get("b")
category = self.request.get('cg')
q = self.request.get('q').encode("utf-8")
w = self.request.get('q')
cg = self.request.get('cg')
t = self.request.get('t')
f = self.request.get('f')
if bookmark:
bookmark = datetime.strftime(bookmark[:-7], "%Y-%m-%d %H:%M:%S")
else:
bookmark = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")
if cg and not t and not q and not f:
entit开发者_C百科ies = Entity.all().filter("category =", cg).filter("modified >", timeline).filter("published =", True).filter("modified <=", bookmark )...
datetime.strptime returns a datetime object from a string (given a formatting parameter). It sounds like you are looking to do the opposite (return a formatted string from a datetime object), which would be datetime.strftime. Using "%Y-%m-%d %H:%M:%S" as your formatting in conjunction with strftime should give you the output you are looking for.
精彩评论