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

标签 datetime grails time groovy

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

关于datetime - Grails-如果少于10分钟,则比较Groovy日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24076865/

相关文章:

mysql - 使用 CONVERT_TZ 12k+ 记录将东部时区批量转换为 gmt

security - 表单中Grails隐藏ID字段的替代方法

grails - Grails脚手架模板-从域类获取属性

grails - 管理员角色能否在Spring-security ACL Grails中获得其他用户的权限

php - 如何使用 SLEEP() 函数在 PHP 中暂停脚本几分之一秒?

python - 如何在python中获取5分钟前的时间

C# 日期时间数组

java - 无法从 HH :mm:ss. SSS'Z' 转换为 HH:MM 格式 Java

java - 区间和的时间复杂度

android - gps 时间与设备时间