Grails - 比较Groovy日期时间少于10分钟

bin*_*iam 1 time grails groovy datetime

如果它们之间的差异小于10分钟,我想比较两个日期.我怎么做?

Date created = Date.parse('yyyy-MM-dd HH:mm:ss','2014-06-05 10:19:04')

Date now = new Date()

now.compareTo(created) gives me 1 but I want to compare the minute difference.
Run Code Online (Sandbox Code Playgroud)

Psy*_*nch 9

尝试使用java.util.concurrent.TimeUnit.我假设,Groovy Date.parse创造了java.util.Date.

def difference = now.time - created.time
if (difference < TimeUnit.MINUTES.toMillis(10)) {
    //do something
}
Run Code Online (Sandbox Code Playgroud)