2011-02-27 24 views

回答

2
class Record { 
    DateTime dateField 

    def getAllRecordsForOneDay(aDay = new DateTime()) { 
    def localDate = new LocalDate(aDay); 
    Record.findAllDateFieldBetween(localDate.toDateTimeAtStartOfDay(), localDate.plusDays(1).toDateTimeAtStartOfDay()) 
    //Or with criteria 
    Record.withCriteria { 
     between 'dateField', localDate.toDateTimeAtStartOfDay(), localDate.plusDays(1).toDateTimeAtStartOfDay() 
    } 

    } 

} 
+0

localDate.toDateTimeAtStartOfDay()和localDate.toDateTimeAtMidnight()都返回相同的结果,所以查询不会返回任何东西:( – 2011-02-28 12:34:35

+0

好吧所以我更新了我的答案localDate.plusDays(1) – fabien7474 2011-02-28 19:44:41

相关问题