本文介绍了如何将GAE TimeProperty转换为整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在中有以下代码:

>>> dt = DateTime('Mar 9, 1997 13:45:00 US/Eastern')
>>> dt.timeTime()
857933100.0

我会使用这个包,但是有一个警告: 除非您需要与Zope 2 API进行沟通,否则您最好使用Python的bult-in datetime模块。

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 给我这样的东西 02:37:31.797000 如何将其转换为一个数字,如在示例中,以便我可以添加一个整数它按照新的值排序。我想实现某种加权排序。谢谢。

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.

编辑

@Robert Kluin:

@Robert Kluin:

谢谢这样做:

>>> today = datetime.datetime.today().toordinal()
>>> today
734086
>>>

但是我有一个在查询中使用的DateTime对象进行排序;所以这样做:

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) 

我收到错误:

PropertyError: Invalid property name '(datetime.datetime.mDATE.toordinal())'

这是模板打印的 mDATE 的值:

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


推荐答案

查看模块。

import time
value = time.time()

这篇关于如何将GAE TimeProperty转换为整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 04:38