'Need to check whether the given time stamp is less than 30 minutes or not using groovy

I am getting the time stamp in the format of (dd.mm.yyyy:hh24:mi:ss)(02.03.2022:00:04:14)

i need to check whether the obtained value is 30 minutes less than the current time using groovy

can someone please help me in solving this problem.

thanks in advance.



Solution 1:[1]

Here is what I'd do:

import java.util.concurrent.TimeUnit

String ts = "05.03.2022:03:36:00"

boolean isWithinTheLast( Date timestamp, int minutes ) {
   return (System.currentTimeMillis() - timestamp.time) <= TimeUnit.MINUTES.toMillis(30)
}

Date timestamp = Date.parse("dd.MM.yyyy:HH:mm:ss", ts)
println( new Date() )
println( timestamp )
println( isWithinTheLast( timestamp, 30) )    

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 chubbsondubs