繁体   English   中英

Grails-如果少于10分钟,则比较Groovy日期时间

[英]Grails - Compare Groovy Date Time if less than 10 minutes

如果两个日期之间的差异小于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.

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

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

暂无
暂无

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

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