Is there a way to get the current ‘date’ and ‘time’, modify them and use as a new input ?


In our case we need to populate a calendar with a future value, say ‘today’s date + 3 days’. Same for the current time. Is there a way to get the current date, modify it and use as an input in our test cases ?

Example: our application accept the following date format 05/17/17 (mm/dd/yy).
If today is 05/17/17 we need to slightly modify that(+ 3 days), so we have 05/20/17 and then populate the input filed with the new value.



Here it is:

import groovy.time.TimeCategory

use (groovy.time.TimeCategory) {

// application on numbers:


println 10.hours.ago

// application on dates

def someDate = new Date()

println someDate + 3.days



use(TimeCategory) {

AnyDate= now + 1.week - 4.days + 2.hours - 3.seconds

println AnyDate

String NewDate2 = AnyDate.format(‘MM/dd/yy’)

println ('NewDate2 = ’ + NewDate2)


Still wasn’t able to find how to set up a future date/time but the following code works well when using today’s date/time:
Date today = new Date()
String todaysDate = today.format(‘mm/dd/yy’)
String nowTime = today.format(‘hh:mm a’)
println (nowTime)


01:18 PM