简体   繁体   English

如何将GAE TimeProperty转换为整数?

[英]How do I convert GAE TimeProperty to integer?

In this Python package there is this code: 此Python包中有以下代码:

>>> 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." 我将使用此软件包,但有一个警告:“除非您需要与Zope 2 API通信,否则最好使用Python的bult-in datetime模块。”

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. GAE中的TimeProperty给了我类似的内容02:37:31.797000如何将它转换为示例中的数字,以便可以向其中添加一个整数并按新值进行排序。 I want to achieve some kind of weighed sort. 我想实现某种权衡。 Thanks. 谢谢。

EDIT 编辑

@Robert Kluin: @罗伯特·克鲁因(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; 但是我在查询中使用了DateTime对象进行排序; 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的值:

mDATE = 2010-11-10 05:38:55.340000 

Check out the time module. 检出时间模块。

import time
value = time.time()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM