想象我有这个 Realm 类:
class Event {
DateTime startDate
DateTime endDate
}
我想找到在过去15到30分钟内结束的 Activity 。
我想要类似的东西:
def now = DateTime.now()
def events= Event.withCriteria {
ge("endDate".plusMinutes(15), now)
ge("endDate".plusMinutes(30), now)
}
最佳答案
你也可以用普通的日期魔术来做到这一点
def events= Event.withCriteria {
between "endDate", new Date( now.time - 30 * 60 * 1000 ), new Date( now.time - 15 * 60 * 1000 )
}
关于grails - 基于日期的Grails查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30755528/