How do I convert GAE TimeProperty to integer?
In this Python package there is this code:
>>> dt = DateTime('Mar 9, 1997 13:45:00 US/Eastern')
>>> dt.timeTime()
857933100.0
I would use this package but there is a warning: "Unless you need to 开发者_运维百科communicate with Zope 2 APIs, you're probably better off using Python's bult-in datetime module."
TimeProperty
in GAE gives me something like this 02:37:31.797000
How do I convert it to a number as in the example so that I can add an integer to it and sort by the new value. I want to achieve some kind of weighed sort. Thanks.
EDIT
@Robert Kluin:
Thanks; this works:
>>> today = datetime.datetime.today().toordinal()
>>> today
734086
>>>
But I have a DateTime object that I am using in the query to sort; so this works:
QUERY2 = Rep.all()
QUERY2.filter("mAUTHOR =", user)
QUERY2.order("-mDATE")
RESULTS2 = QUERY2.fetch(10)
But when I try this, it does not work:
QUERY2 = Rep.all()
QUERY2.filter("mAUTHOR =", user)
QUERY2.order("-(datetime.datetime.mDATE.toordinal())")
RESULTS2 = QUERY2.fetch(10)
I get the error:
PropertyError: Invalid property name '(datetime.datetime.mDATE.toordinal())'
This is the value of mDATE
as printed by the template:
mDATE = 2010-11-10 05:38:55.340000
Check out the time module.
import time
value = time.time()
精彩评论