How do I add seconds to now() function using Groovy?
Consider replacing now()
with
System.currentTimeMillis()
which returns a long value in
milliseconds.
In Java (Groovy) time is based on the number of milliseconds before or after Jan 1 1970 UTC. For example, you can add 10 seconds or 10000 milliseconds (10 seconds * 1000 milliseconds per second) to get time of 10 seconds into the future.
Here's how
def current = new().getTime();
def future = current + 10*1000; //adding 10 seconds + 1000 milliseconds per second
if (future > current) {
…
}