I want to compare two dates if the difference between them is less than 10 minutes. How do I do that?
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.
Try using java.util.concurrent.TimeUnit
. I'm assuming that, Groovy Date.parse
creates java.util.Date
, though.
def difference = now.time - created.time
if (difference < TimeUnit.MINUTES.toMillis(10)) {
//do something
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.